{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### W1-冯炳驹-124298228"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 亚美尼亚州洛瓦市房价预测"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "导入必要的工具包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 数据读取及基本处理\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "#查看数据分布是否对称/计算斜度\n",
    "from scipy.stats import skew\n",
    "\n",
    "#可视化\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "\n",
    "from IPython.display import display\n",
    "# Definitions\n",
    "pd.set_option('display.float_format', lambda x: '%.3f' % x)\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>MSSubClass</th>\n",
       "      <th>MSZoning</th>\n",
       "      <th>LotFrontage</th>\n",
       "      <th>LotArea</th>\n",
       "      <th>Street</th>\n",
       "      <th>Alley</th>\n",
       "      <th>LotShape</th>\n",
       "      <th>LandContour</th>\n",
       "      <th>Utilities</th>\n",
       "      <th>...</th>\n",
       "      <th>PoolArea</th>\n",
       "      <th>PoolQC</th>\n",
       "      <th>Fence</th>\n",
       "      <th>MiscFeature</th>\n",
       "      <th>MiscVal</th>\n",
       "      <th>MoSold</th>\n",
       "      <th>YrSold</th>\n",
       "      <th>SaleType</th>\n",
       "      <th>SaleCondition</th>\n",
       "      <th>SalePrice</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>60</td>\n",
       "      <td>RL</td>\n",
       "      <td>65.000</td>\n",
       "      <td>8450</td>\n",
       "      <td>Pave</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Reg</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2008</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>208500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>20</td>\n",
       "      <td>RL</td>\n",
       "      <td>80.000</td>\n",
       "      <td>9600</td>\n",
       "      <td>Pave</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Reg</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>2007</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>181500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>60</td>\n",
       "      <td>RL</td>\n",
       "      <td>68.000</td>\n",
       "      <td>11250</td>\n",
       "      <td>Pave</td>\n",
       "      <td>NaN</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>2008</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>223500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>70</td>\n",
       "      <td>RL</td>\n",
       "      <td>60.000</td>\n",
       "      <td>9550</td>\n",
       "      <td>Pave</td>\n",
       "      <td>NaN</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2006</td>\n",
       "      <td>WD</td>\n",
       "      <td>Abnorml</td>\n",
       "      <td>140000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>60</td>\n",
       "      <td>RL</td>\n",
       "      <td>84.000</td>\n",
       "      <td>14260</td>\n",
       "      <td>Pave</td>\n",
       "      <td>NaN</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>12</td>\n",
       "      <td>2008</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>250000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>50</td>\n",
       "      <td>RL</td>\n",
       "      <td>85.000</td>\n",
       "      <td>14115</td>\n",
       "      <td>Pave</td>\n",
       "      <td>NaN</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>MnPrv</td>\n",
       "      <td>Shed</td>\n",
       "      <td>700</td>\n",
       "      <td>10</td>\n",
       "      <td>2009</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>143000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>20</td>\n",
       "      <td>RL</td>\n",
       "      <td>75.000</td>\n",
       "      <td>10084</td>\n",
       "      <td>Pave</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Reg</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "      <td>2007</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>307000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>60</td>\n",
       "      <td>RL</td>\n",
       "      <td>nan</td>\n",
       "      <td>10382</td>\n",
       "      <td>Pave</td>\n",
       "      <td>NaN</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Shed</td>\n",
       "      <td>350</td>\n",
       "      <td>11</td>\n",
       "      <td>2009</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>200000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>50</td>\n",
       "      <td>RM</td>\n",
       "      <td>51.000</td>\n",
       "      <td>6120</td>\n",
       "      <td>Pave</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Reg</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>2008</td>\n",
       "      <td>WD</td>\n",
       "      <td>Abnorml</td>\n",
       "      <td>129900</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>190</td>\n",
       "      <td>RL</td>\n",
       "      <td>50.000</td>\n",
       "      <td>7420</td>\n",
       "      <td>Pave</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Reg</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2008</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>118000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>10 rows × 81 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   Id  MSSubClass MSZoning  LotFrontage  LotArea Street Alley LotShape  \\\n",
       "0   1          60       RL       65.000     8450   Pave   NaN      Reg   \n",
       "1   2          20       RL       80.000     9600   Pave   NaN      Reg   \n",
       "2   3          60       RL       68.000    11250   Pave   NaN      IR1   \n",
       "3   4          70       RL       60.000     9550   Pave   NaN      IR1   \n",
       "4   5          60       RL       84.000    14260   Pave   NaN      IR1   \n",
       "5   6          50       RL       85.000    14115   Pave   NaN      IR1   \n",
       "6   7          20       RL       75.000    10084   Pave   NaN      Reg   \n",
       "7   8          60       RL          nan    10382   Pave   NaN      IR1   \n",
       "8   9          50       RM       51.000     6120   Pave   NaN      Reg   \n",
       "9  10         190       RL       50.000     7420   Pave   NaN      Reg   \n",
       "\n",
       "  LandContour Utilities    ...     PoolArea PoolQC  Fence MiscFeature MiscVal  \\\n",
       "0         Lvl    AllPub    ...            0    NaN    NaN         NaN       0   \n",
       "1         Lvl    AllPub    ...            0    NaN    NaN         NaN       0   \n",
       "2         Lvl    AllPub    ...            0    NaN    NaN         NaN       0   \n",
       "3         Lvl    AllPub    ...            0    NaN    NaN         NaN       0   \n",
       "4         Lvl    AllPub    ...            0    NaN    NaN         NaN       0   \n",
       "5         Lvl    AllPub    ...            0    NaN  MnPrv        Shed     700   \n",
       "6         Lvl    AllPub    ...            0    NaN    NaN         NaN       0   \n",
       "7         Lvl    AllPub    ...            0    NaN    NaN        Shed     350   \n",
       "8         Lvl    AllPub    ...            0    NaN    NaN         NaN       0   \n",
       "9         Lvl    AllPub    ...            0    NaN    NaN         NaN       0   \n",
       "\n",
       "  MoSold YrSold  SaleType  SaleCondition  SalePrice  \n",
       "0      2   2008        WD         Normal     208500  \n",
       "1      5   2007        WD         Normal     181500  \n",
       "2      9   2008        WD         Normal     223500  \n",
       "3      2   2006        WD        Abnorml     140000  \n",
       "4     12   2008        WD         Normal     250000  \n",
       "5     10   2009        WD         Normal     143000  \n",
       "6      8   2007        WD         Normal     307000  \n",
       "7     11   2009        WD         Normal     200000  \n",
       "8      4   2008        WD        Abnorml     129900  \n",
       "9      1   2008        WD         Normal     118000  \n",
       "\n",
       "[10 rows x 81 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# path to where the data lies\n",
    "train_data = pd.read_csv(\"Ames_House_train.csv\")\n",
    "train_data.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1460 entries, 0 to 1459\n",
      "Data columns (total 81 columns):\n",
      "Id               1460 non-null int64\n",
      "MSSubClass       1460 non-null int64\n",
      "MSZoning         1460 non-null object\n",
      "LotFrontage      1201 non-null float64\n",
      "LotArea          1460 non-null int64\n",
      "Street           1460 non-null object\n",
      "Alley            91 non-null object\n",
      "LotShape         1460 non-null object\n",
      "LandContour      1460 non-null object\n",
      "Utilities        1460 non-null object\n",
      "LotConfig        1460 non-null object\n",
      "LandSlope        1460 non-null object\n",
      "Neighborhood     1460 non-null object\n",
      "Condition1       1460 non-null object\n",
      "Condition2       1460 non-null object\n",
      "BldgType         1460 non-null object\n",
      "HouseStyle       1460 non-null object\n",
      "OverallQual      1460 non-null int64\n",
      "OverallCond      1460 non-null int64\n",
      "YearBuilt        1460 non-null int64\n",
      "YearRemodAdd     1460 non-null int64\n",
      "RoofStyle        1460 non-null object\n",
      "RoofMatl         1460 non-null object\n",
      "Exterior1st      1460 non-null object\n",
      "Exterior2nd      1460 non-null object\n",
      "MasVnrType       1452 non-null object\n",
      "MasVnrArea       1452 non-null float64\n",
      "ExterQual        1460 non-null object\n",
      "ExterCond        1460 non-null object\n",
      "Foundation       1460 non-null object\n",
      "BsmtQual         1423 non-null object\n",
      "BsmtCond         1423 non-null object\n",
      "BsmtExposure     1422 non-null object\n",
      "BsmtFinType1     1423 non-null object\n",
      "BsmtFinSF1       1460 non-null int64\n",
      "BsmtFinType2     1422 non-null object\n",
      "BsmtFinSF2       1460 non-null int64\n",
      "BsmtUnfSF        1460 non-null int64\n",
      "TotalBsmtSF      1460 non-null int64\n",
      "Heating          1460 non-null object\n",
      "HeatingQC        1460 non-null object\n",
      "CentralAir       1460 non-null object\n",
      "Electrical       1459 non-null object\n",
      "1stFlrSF         1460 non-null int64\n",
      "2ndFlrSF         1460 non-null int64\n",
      "LowQualFinSF     1460 non-null int64\n",
      "GrLivArea        1460 non-null int64\n",
      "BsmtFullBath     1460 non-null int64\n",
      "BsmtHalfBath     1460 non-null int64\n",
      "FullBath         1460 non-null int64\n",
      "HalfBath         1460 non-null int64\n",
      "BedroomAbvGr     1460 non-null int64\n",
      "KitchenAbvGr     1460 non-null int64\n",
      "KitchenQual      1460 non-null object\n",
      "TotRmsAbvGrd     1460 non-null int64\n",
      "Functional       1460 non-null object\n",
      "Fireplaces       1460 non-null int64\n",
      "FireplaceQu      770 non-null object\n",
      "GarageType       1379 non-null object\n",
      "GarageYrBlt      1379 non-null float64\n",
      "GarageFinish     1379 non-null object\n",
      "GarageCars       1460 non-null int64\n",
      "GarageArea       1460 non-null int64\n",
      "GarageQual       1379 non-null object\n",
      "GarageCond       1379 non-null object\n",
      "PavedDrive       1460 non-null object\n",
      "WoodDeckSF       1460 non-null int64\n",
      "OpenPorchSF      1460 non-null int64\n",
      "EnclosedPorch    1460 non-null int64\n",
      "3SsnPorch        1460 non-null int64\n",
      "ScreenPorch      1460 non-null int64\n",
      "PoolArea         1460 non-null int64\n",
      "PoolQC           7 non-null object\n",
      "Fence            281 non-null object\n",
      "MiscFeature      54 non-null object\n",
      "MiscVal          1460 non-null int64\n",
      "MoSold           1460 non-null int64\n",
      "YrSold           1460 non-null int64\n",
      "SaleType         1460 non-null object\n",
      "SaleCondition    1460 non-null object\n",
      "SalePrice        1460 non-null int64\n",
      "dtypes: float64(3), int64(35), object(43)\n",
      "memory usage: 924.0+ KB\n"
     ]
    }
   ],
   "source": [
    "train_data.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1459 entries, 0 to 1458\n",
      "Data columns (total 80 columns):\n",
      "Id               1459 non-null int64\n",
      "MSSubClass       1459 non-null int64\n",
      "MSZoning         1455 non-null object\n",
      "LotFrontage      1232 non-null float64\n",
      "LotArea          1459 non-null int64\n",
      "Street           1459 non-null object\n",
      "Alley            107 non-null object\n",
      "LotShape         1459 non-null object\n",
      "LandContour      1459 non-null object\n",
      "Utilities        1457 non-null object\n",
      "LotConfig        1459 non-null object\n",
      "LandSlope        1459 non-null object\n",
      "Neighborhood     1459 non-null object\n",
      "Condition1       1459 non-null object\n",
      "Condition2       1459 non-null object\n",
      "BldgType         1459 non-null object\n",
      "HouseStyle       1459 non-null object\n",
      "OverallQual      1459 non-null int64\n",
      "OverallCond      1459 non-null int64\n",
      "YearBuilt        1459 non-null int64\n",
      "YearRemodAdd     1459 non-null int64\n",
      "RoofStyle        1459 non-null object\n",
      "RoofMatl         1459 non-null object\n",
      "Exterior1st      1458 non-null object\n",
      "Exterior2nd      1458 non-null object\n",
      "MasVnrType       1443 non-null object\n",
      "MasVnrArea       1444 non-null float64\n",
      "ExterQual        1459 non-null object\n",
      "ExterCond        1459 non-null object\n",
      "Foundation       1459 non-null object\n",
      "BsmtQual         1415 non-null object\n",
      "BsmtCond         1414 non-null object\n",
      "BsmtExposure     1415 non-null object\n",
      "BsmtFinType1     1417 non-null object\n",
      "BsmtFinSF1       1458 non-null float64\n",
      "BsmtFinType2     1417 non-null object\n",
      "BsmtFinSF2       1458 non-null float64\n",
      "BsmtUnfSF        1458 non-null float64\n",
      "TotalBsmtSF      1458 non-null float64\n",
      "Heating          1459 non-null object\n",
      "HeatingQC        1459 non-null object\n",
      "CentralAir       1459 non-null object\n",
      "Electrical       1459 non-null object\n",
      "1stFlrSF         1459 non-null int64\n",
      "2ndFlrSF         1459 non-null int64\n",
      "LowQualFinSF     1459 non-null int64\n",
      "GrLivArea        1459 non-null int64\n",
      "BsmtFullBath     1457 non-null float64\n",
      "BsmtHalfBath     1457 non-null float64\n",
      "FullBath         1459 non-null int64\n",
      "HalfBath         1459 non-null int64\n",
      "BedroomAbvGr     1459 non-null int64\n",
      "KitchenAbvGr     1459 non-null int64\n",
      "KitchenQual      1458 non-null object\n",
      "TotRmsAbvGrd     1459 non-null int64\n",
      "Functional       1457 non-null object\n",
      "Fireplaces       1459 non-null int64\n",
      "FireplaceQu      729 non-null object\n",
      "GarageType       1383 non-null object\n",
      "GarageYrBlt      1381 non-null float64\n",
      "GarageFinish     1381 non-null object\n",
      "GarageCars       1458 non-null float64\n",
      "GarageArea       1458 non-null float64\n",
      "GarageQual       1381 non-null object\n",
      "GarageCond       1381 non-null object\n",
      "PavedDrive       1459 non-null object\n",
      "WoodDeckSF       1459 non-null int64\n",
      "OpenPorchSF      1459 non-null int64\n",
      "EnclosedPorch    1459 non-null int64\n",
      "3SsnPorch        1459 non-null int64\n",
      "ScreenPorch      1459 non-null int64\n",
      "PoolArea         1459 non-null int64\n",
      "PoolQC           3 non-null object\n",
      "Fence            290 non-null object\n",
      "MiscFeature      51 non-null object\n",
      "MiscVal          1459 non-null int64\n",
      "MoSold           1459 non-null int64\n",
      "YrSold           1459 non-null int64\n",
      "SaleType         1458 non-null object\n",
      "SaleCondition    1459 non-null object\n",
      "dtypes: float64(11), int64(26), object(43)\n",
      "memory usage: 911.9+ KB\n"
     ]
    }
   ],
   "source": [
    "test_data = pd.read_csv(\"Ames_House_test.csv\")\n",
    "test_data.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Id                  0\n",
       "MSSubClass          0\n",
       "MSZoning            0\n",
       "LotFrontage       259\n",
       "LotArea             0\n",
       "Street              0\n",
       "Alley            1369\n",
       "LotShape            0\n",
       "LandContour         0\n",
       "Utilities           0\n",
       "LotConfig           0\n",
       "LandSlope           0\n",
       "Neighborhood        0\n",
       "Condition1          0\n",
       "Condition2          0\n",
       "BldgType            0\n",
       "HouseStyle          0\n",
       "OverallQual         0\n",
       "OverallCond         0\n",
       "YearBuilt           0\n",
       "YearRemodAdd        0\n",
       "RoofStyle           0\n",
       "RoofMatl            0\n",
       "Exterior1st         0\n",
       "Exterior2nd         0\n",
       "MasVnrType          8\n",
       "MasVnrArea          8\n",
       "ExterQual           0\n",
       "ExterCond           0\n",
       "Foundation          0\n",
       "                 ... \n",
       "BedroomAbvGr        0\n",
       "KitchenAbvGr        0\n",
       "KitchenQual         0\n",
       "TotRmsAbvGrd        0\n",
       "Functional          0\n",
       "Fireplaces          0\n",
       "FireplaceQu       690\n",
       "GarageType         81\n",
       "GarageYrBlt        81\n",
       "GarageFinish       81\n",
       "GarageCars          0\n",
       "GarageArea          0\n",
       "GarageQual         81\n",
       "GarageCond         81\n",
       "PavedDrive          0\n",
       "WoodDeckSF          0\n",
       "OpenPorchSF         0\n",
       "EnclosedPorch       0\n",
       "3SsnPorch           0\n",
       "ScreenPorch         0\n",
       "PoolArea            0\n",
       "PoolQC           1453\n",
       "Fence            1179\n",
       "MiscFeature      1406\n",
       "MiscVal             0\n",
       "MoSold              0\n",
       "YrSold              0\n",
       "SaleType            0\n",
       "SaleCondition       0\n",
       "SalePrice           0\n",
       "Length: 81, dtype: int64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "### 查看是否有空值\n",
    "train_data.isnull().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1460, 81)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>MSSubClass</th>\n",
       "      <th>LotFrontage</th>\n",
       "      <th>LotArea</th>\n",
       "      <th>OverallQual</th>\n",
       "      <th>OverallCond</th>\n",
       "      <th>YearBuilt</th>\n",
       "      <th>YearRemodAdd</th>\n",
       "      <th>MasVnrArea</th>\n",
       "      <th>BsmtFinSF1</th>\n",
       "      <th>...</th>\n",
       "      <th>WoodDeckSF</th>\n",
       "      <th>OpenPorchSF</th>\n",
       "      <th>EnclosedPorch</th>\n",
       "      <th>3SsnPorch</th>\n",
       "      <th>ScreenPorch</th>\n",
       "      <th>PoolArea</th>\n",
       "      <th>MiscVal</th>\n",
       "      <th>MoSold</th>\n",
       "      <th>YrSold</th>\n",
       "      <th>SalePrice</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>1460.000</td>\n",
       "      <td>1460.000</td>\n",
       "      <td>1201.000</td>\n",
       "      <td>1460.000</td>\n",
       "      <td>1460.000</td>\n",
       "      <td>1460.000</td>\n",
       "      <td>1460.000</td>\n",
       "      <td>1460.000</td>\n",
       "      <td>1452.000</td>\n",
       "      <td>1460.000</td>\n",
       "      <td>...</td>\n",
       "      <td>1460.000</td>\n",
       "      <td>1460.000</td>\n",
       "      <td>1460.000</td>\n",
       "      <td>1460.000</td>\n",
       "      <td>1460.000</td>\n",
       "      <td>1460.000</td>\n",
       "      <td>1460.000</td>\n",
       "      <td>1460.000</td>\n",
       "      <td>1460.000</td>\n",
       "      <td>1460.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>730.500</td>\n",
       "      <td>56.897</td>\n",
       "      <td>70.050</td>\n",
       "      <td>10516.828</td>\n",
       "      <td>6.099</td>\n",
       "      <td>5.575</td>\n",
       "      <td>1971.268</td>\n",
       "      <td>1984.866</td>\n",
       "      <td>103.685</td>\n",
       "      <td>443.640</td>\n",
       "      <td>...</td>\n",
       "      <td>94.245</td>\n",
       "      <td>46.660</td>\n",
       "      <td>21.954</td>\n",
       "      <td>3.410</td>\n",
       "      <td>15.061</td>\n",
       "      <td>2.759</td>\n",
       "      <td>43.489</td>\n",
       "      <td>6.322</td>\n",
       "      <td>2007.816</td>\n",
       "      <td>180921.196</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>421.610</td>\n",
       "      <td>42.301</td>\n",
       "      <td>24.285</td>\n",
       "      <td>9981.265</td>\n",
       "      <td>1.383</td>\n",
       "      <td>1.113</td>\n",
       "      <td>30.203</td>\n",
       "      <td>20.645</td>\n",
       "      <td>181.066</td>\n",
       "      <td>456.098</td>\n",
       "      <td>...</td>\n",
       "      <td>125.339</td>\n",
       "      <td>66.256</td>\n",
       "      <td>61.119</td>\n",
       "      <td>29.317</td>\n",
       "      <td>55.757</td>\n",
       "      <td>40.177</td>\n",
       "      <td>496.123</td>\n",
       "      <td>2.704</td>\n",
       "      <td>1.328</td>\n",
       "      <td>79442.503</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>1.000</td>\n",
       "      <td>20.000</td>\n",
       "      <td>21.000</td>\n",
       "      <td>1300.000</td>\n",
       "      <td>1.000</td>\n",
       "      <td>1.000</td>\n",
       "      <td>1872.000</td>\n",
       "      <td>1950.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>1.000</td>\n",
       "      <td>2006.000</td>\n",
       "      <td>34900.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>365.750</td>\n",
       "      <td>20.000</td>\n",
       "      <td>59.000</td>\n",
       "      <td>7553.500</td>\n",
       "      <td>5.000</td>\n",
       "      <td>5.000</td>\n",
       "      <td>1954.000</td>\n",
       "      <td>1967.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>5.000</td>\n",
       "      <td>2007.000</td>\n",
       "      <td>129975.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>730.500</td>\n",
       "      <td>50.000</td>\n",
       "      <td>69.000</td>\n",
       "      <td>9478.500</td>\n",
       "      <td>6.000</td>\n",
       "      <td>5.000</td>\n",
       "      <td>1973.000</td>\n",
       "      <td>1994.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>383.500</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>25.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>6.000</td>\n",
       "      <td>2008.000</td>\n",
       "      <td>163000.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1095.250</td>\n",
       "      <td>70.000</td>\n",
       "      <td>80.000</td>\n",
       "      <td>11601.500</td>\n",
       "      <td>7.000</td>\n",
       "      <td>6.000</td>\n",
       "      <td>2000.000</td>\n",
       "      <td>2004.000</td>\n",
       "      <td>166.000</td>\n",
       "      <td>712.250</td>\n",
       "      <td>...</td>\n",
       "      <td>168.000</td>\n",
       "      <td>68.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>8.000</td>\n",
       "      <td>2009.000</td>\n",
       "      <td>214000.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>1460.000</td>\n",
       "      <td>190.000</td>\n",
       "      <td>313.000</td>\n",
       "      <td>215245.000</td>\n",
       "      <td>10.000</td>\n",
       "      <td>9.000</td>\n",
       "      <td>2010.000</td>\n",
       "      <td>2010.000</td>\n",
       "      <td>1600.000</td>\n",
       "      <td>5644.000</td>\n",
       "      <td>...</td>\n",
       "      <td>857.000</td>\n",
       "      <td>547.000</td>\n",
       "      <td>552.000</td>\n",
       "      <td>508.000</td>\n",
       "      <td>480.000</td>\n",
       "      <td>738.000</td>\n",
       "      <td>15500.000</td>\n",
       "      <td>12.000</td>\n",
       "      <td>2010.000</td>\n",
       "      <td>755000.000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8 rows × 38 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            Id  MSSubClass  LotFrontage    LotArea  OverallQual  OverallCond  \\\n",
       "count 1460.000    1460.000     1201.000   1460.000     1460.000     1460.000   \n",
       "mean   730.500      56.897       70.050  10516.828        6.099        5.575   \n",
       "std    421.610      42.301       24.285   9981.265        1.383        1.113   \n",
       "min      1.000      20.000       21.000   1300.000        1.000        1.000   \n",
       "25%    365.750      20.000       59.000   7553.500        5.000        5.000   \n",
       "50%    730.500      50.000       69.000   9478.500        6.000        5.000   \n",
       "75%   1095.250      70.000       80.000  11601.500        7.000        6.000   \n",
       "max   1460.000     190.000      313.000 215245.000       10.000        9.000   \n",
       "\n",
       "       YearBuilt  YearRemodAdd  MasVnrArea  BsmtFinSF1    ...      WoodDeckSF  \\\n",
       "count   1460.000      1460.000    1452.000    1460.000    ...        1460.000   \n",
       "mean    1971.268      1984.866     103.685     443.640    ...          94.245   \n",
       "std       30.203        20.645     181.066     456.098    ...         125.339   \n",
       "min     1872.000      1950.000       0.000       0.000    ...           0.000   \n",
       "25%     1954.000      1967.000       0.000       0.000    ...           0.000   \n",
       "50%     1973.000      1994.000       0.000     383.500    ...           0.000   \n",
       "75%     2000.000      2004.000     166.000     712.250    ...         168.000   \n",
       "max     2010.000      2010.000    1600.000    5644.000    ...         857.000   \n",
       "\n",
       "       OpenPorchSF  EnclosedPorch  3SsnPorch  ScreenPorch  PoolArea   MiscVal  \\\n",
       "count     1460.000       1460.000   1460.000     1460.000  1460.000  1460.000   \n",
       "mean        46.660         21.954      3.410       15.061     2.759    43.489   \n",
       "std         66.256         61.119     29.317       55.757    40.177   496.123   \n",
       "min          0.000          0.000      0.000        0.000     0.000     0.000   \n",
       "25%          0.000          0.000      0.000        0.000     0.000     0.000   \n",
       "50%         25.000          0.000      0.000        0.000     0.000     0.000   \n",
       "75%         68.000          0.000      0.000        0.000     0.000     0.000   \n",
       "max        547.000        552.000    508.000      480.000   738.000 15500.000   \n",
       "\n",
       "        MoSold   YrSold  SalePrice  \n",
       "count 1460.000 1460.000   1460.000  \n",
       "mean     6.322 2007.816 180921.196  \n",
       "std      2.704    1.328  79442.503  \n",
       "min      1.000 2006.000  34900.000  \n",
       "25%      5.000 2007.000 129975.000  \n",
       "50%      6.000 2008.000 163000.000  \n",
       "75%      8.000 2009.000 214000.000  \n",
       "max     12.000 2010.000 755000.000  \n",
       "\n",
       "[8 rows x 38 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count     1460.000\n",
       "mean    180921.196\n",
       "std      79442.503\n",
       "min      34900.000\n",
       "25%     129975.000\n",
       "50%     163000.000\n",
       "75%     214000.000\n",
       "max     755000.000\n",
       "Name: SalePrice, dtype: float64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data.SalePrice.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#data.drop('Alley', axis=1, inplace=True)\n",
    "##data.drop('FireplaceQu', axis=1, inplace=True)\n",
    "#data.drop('PoolQC', axis=1, inplace=True)\n",
    "#data.drop('Fence', axis=1, inplace=True)\n",
    "#data.drop('MiscFeature', axis=1, inplace=True)\n",
    "#data.isnull().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('skew is :', 1.8828757597682129)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAENCAYAAAABh67pAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAFjBJREFUeJzt3X2QXXd93/H3BwvbPMsPa48iyQgH\nFXA7wTgqluuEEkwIchLkP/CMDa1V1x1lUreFgZSaMNOWmXSATgvE047BxSQiwQTHQK2hLqCRYToJ\ntUAGYx6M47VrrI2MtcZYPDiQgr/94/wWXeR9uCvdq7s6fb9m7pxzfud3z++7e3c/e/bcc85NVSFJ\n6q+nTLoASdJ4GfSS1HMGvST1nEEvST1n0EtSzxn0ktRzBr0k9ZxBL0k9Z9BLUs+tmnQBAKeffnpt\n2LBh0mVI0nHljjvueKSqppbqtyKCfsOGDezdu3fSZUjScSXJt4bp56EbSeo5g16Ses6gl6SeM+gl\nqecMeknqOYNeknrOoJeknjPoJannDHpJ6rkVcWXs8erGPQ9OZNzXnX/WRMaVdHxyj16Ses6gl6Se\nWzLok7wgyZ0Dj+8leWOSU5PsSnJvm57S+ifJtUmmk9yV5LzxfxmSpIUsGfRVdU9VnVtV5wK/DDwO\nfAK4BthdVRuB3W0ZYAuwsT22A9eNo3BJ0nCWe+jmIuC+qvoWsBXY0dp3AJe0+a3Ah6pzO7A6yZqR\nVCtJWrblBv1lwEfa/JlV9RBAm57R2tcC+waeM9Pafk6S7Un2Jtk7Ozu7zDIkScMaOuiTnAi8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n+g+gegf0H1oxVuAJ5KsBf4H8Aet/feAjyWZWvrLlpbPoNdx\nqbpbN8/dF+i/AbNJdiY5s6qmq2pXVf24qmaBd9MF+Xx+h+6eMjNV9WO6PwivzaG7TkJ3J8pHgQ/Q\nfWrQ7oF176iqR6vqbwY3muQpdPdHeUNV/XX7r+PzbYx/BNxaVbdW1RNVtYvuvjEXH913RZqfx+h1\n3Kqqu4F/ApDkhcCfAu9N8ga6z+/8VbqPY3wK3Z76fJ4LfCLJEwNtPwXOHFg+fZHj7/sWaD+d7gZp\n9y0w5qVJfnug7al0d7uURs49evVCVX0T+GO64+fvoNvT/6WqejbdHvR8HxIBXVBvqarVA4+Tq+qv\nhx16gfZHgB8Bv7jAmH9y2JjPqKp3DjmmtCwGvY5LSV6Y5M1J1rXl9XT3Hb+dbi/+B8Bj7Xj4v15k\nU+8D/kOS57btTCXZerT1VdUTwAeBdyf5hXQfu3hBkpPo/vP47SS/0dpPTvLyua9FGjWDXser79O9\nCbonyQ/pAv5rwJuBt9N94tFBujc9P77QRoA/pPuQiM8k+X7bzvkjqvH36O5r/kW6Y/zvAp5SVfuA\nrcDv03326j66P0b+PmosvB+9JPWcexCS1HMGvST1nEEvST1n0EtSzxn0ktRzBr0k9ZxBL0k9Z9BL\nUs8Z9JLUc/8PlJOcjOiy324AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xcfd9eb8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure()\n",
    "print(\"skew is :\",train_data.SalePrice.skew())\n",
    "sns.distplot(train_data.SalePrice, bins=10, kde=False)\n",
    "#plt.hist(train_data.SalePrice, color = 'blue')\n",
    "plt.xlabel('SalePrice', fontsize=12)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "MSZoning属性的不同取值和出现的次数\n",
      "RL         1151\n",
      "RM          218\n",
      "FV           65\n",
      "RH           16\n",
      "C (all)      10\n",
      "Name: MSZoning, dtype: int64\n",
      "\n",
      "Street属性的不同取值和出现的次数\n",
      "Pave    1454\n",
      "Grvl       6\n",
      "Name: Street, dtype: int64\n",
      "\n",
      "Alley属性的不同取值和出现的次数\n",
      "Grvl    50\n",
      "Pave    41\n",
      "Name: Alley, dtype: int64\n",
      "\n",
      "LotShape属性的不同取值和出现的次数\n",
      "Reg    925\n",
      "IR1    484\n",
      "IR2     41\n",
      "IR3     10\n",
      "Name: LotShape, dtype: int64\n",
      "\n",
      "LandContour属性的不同取值和出现的次数\n",
      "Lvl    1311\n",
      "Bnk      63\n",
      "HLS      50\n",
      "Low      36\n",
      "Name: LandContour, dtype: int64\n",
      "\n",
      "Utilities属性的不同取值和出现的次数\n",
      "AllPub    1459\n",
      "NoSeWa       1\n",
      "Name: Utilities, dtype: int64\n",
      "\n",
      "LotConfig属性的不同取值和出现的次数\n",
      "Inside     1052\n",
      "Corner      263\n",
      "CulDSac      94\n",
      "FR2          47\n",
      "FR3           4\n",
      "Name: LotConfig, dtype: int64\n",
      "\n",
      "LandSlope属性的不同取值和出现的次数\n",
      "Gtl    1382\n",
      "Mod      65\n",
      "Sev      13\n",
      "Name: LandSlope, dtype: int64\n",
      "\n",
      "Neighborhood属性的不同取值和出现的次数\n",
      "NAmes      225\n",
      "CollgCr    150\n",
      "OldTown    113\n",
      "Edwards    100\n",
      "Somerst     86\n",
      "Gilbert     79\n",
      "NridgHt     77\n",
      "Sawyer      74\n",
      "NWAmes      73\n",
      "SawyerW     59\n",
      "BrkSide     58\n",
      "Crawfor     51\n",
      "Mitchel     49\n",
      "NoRidge     41\n",
      "Timber      38\n",
      "IDOTRR      37\n",
      "ClearCr     28\n",
      "SWISU       25\n",
      "StoneBr     25\n",
      "MeadowV     17\n",
      "Blmngtn     17\n",
      "BrDale      16\n",
      "Veenker     11\n",
      "NPkVill      9\n",
      "Blueste      2\n",
      "Name: Neighborhood, dtype: int64\n",
      "\n",
      "Condition1属性的不同取值和出现的次数\n",
      "Norm      1260\n",
      "Feedr       81\n",
      "Artery      48\n",
      "RRAn        26\n",
      "PosN        19\n",
      "RRAe        11\n",
      "PosA         8\n",
      "RRNn         5\n",
      "RRNe         2\n",
      "Name: Condition1, dtype: int64\n",
      "\n",
      "Condition2属性的不同取值和出现的次数\n",
      "Norm      1445\n",
      "Feedr        6\n",
      "Artery       2\n",
      "RRNn         2\n",
      "PosN         2\n",
      "RRAn         1\n",
      "RRAe         1\n",
      "PosA         1\n",
      "Name: Condition2, dtype: int64\n",
      "\n",
      "BldgType属性的不同取值和出现的次数\n",
      "1Fam      1220\n",
      "TwnhsE     114\n",
      "Duplex      52\n",
      "Twnhs       43\n",
      "2fmCon      31\n",
      "Name: BldgType, dtype: int64\n",
      "\n",
      "HouseStyle属性的不同取值和出现的次数\n",
      "1Story    726\n",
      "2Story    445\n",
      "1.5Fin    154\n",
      "SLvl       65\n",
      "SFoyer     37\n",
      "1.5Unf     14\n",
      "2.5Unf     11\n",
      "2.5Fin      8\n",
      "Name: HouseStyle, dtype: int64\n",
      "\n",
      "RoofStyle属性的不同取值和出现的次数\n",
      "Gable      1141\n",
      "Hip         286\n",
      "Flat         13\n",
      "Gambrel      11\n",
      "Mansard       7\n",
      "Shed          2\n",
      "Name: RoofStyle, dtype: int64\n",
      "\n",
      "RoofMatl属性的不同取值和出现的次数\n",
      "CompShg    1434\n",
      "Tar&Grv      11\n",
      "WdShngl       6\n",
      "WdShake       5\n",
      "Membran       1\n",
      "Metal         1\n",
      "ClyTile       1\n",
      "Roll          1\n",
      "Name: RoofMatl, dtype: int64\n",
      "\n",
      "Exterior1st属性的不同取值和出现的次数\n",
      "VinylSd    515\n",
      "HdBoard    222\n",
      "MetalSd    220\n",
      "Wd Sdng    206\n",
      "Plywood    108\n",
      "CemntBd     61\n",
      "BrkFace     50\n",
      "WdShing     26\n",
      "Stucco      25\n",
      "AsbShng     20\n",
      "Stone        2\n",
      "BrkComm      2\n",
      "AsphShn      1\n",
      "ImStucc      1\n",
      "CBlock       1\n",
      "Name: Exterior1st, dtype: int64\n",
      "\n",
      "Exterior2nd属性的不同取值和出现的次数\n",
      "VinylSd    504\n",
      "MetalSd    214\n",
      "HdBoard    207\n",
      "Wd Sdng    197\n",
      "Plywood    142\n",
      "CmentBd     60\n",
      "Wd Shng     38\n",
      "Stucco      26\n",
      "BrkFace     25\n",
      "AsbShng     20\n",
      "ImStucc     10\n",
      "Brk Cmn      7\n",
      "Stone        5\n",
      "AsphShn      3\n",
      "Other        1\n",
      "CBlock       1\n",
      "Name: Exterior2nd, dtype: int64\n",
      "\n",
      "MasVnrType属性的不同取值和出现的次数\n",
      "None       864\n",
      "BrkFace    445\n",
      "Stone      128\n",
      "BrkCmn      15\n",
      "Name: MasVnrType, dtype: int64\n",
      "\n",
      "ExterQual属性的不同取值和出现的次数\n",
      "TA    906\n",
      "Gd    488\n",
      "Ex     52\n",
      "Fa     14\n",
      "Name: ExterQual, dtype: int64\n",
      "\n",
      "ExterCond属性的不同取值和出现的次数\n",
      "TA    1282\n",
      "Gd     146\n",
      "Fa      28\n",
      "Ex       3\n",
      "Po       1\n",
      "Name: ExterCond, dtype: int64\n",
      "\n",
      "Foundation属性的不同取值和出现的次数\n",
      "PConc     647\n",
      "CBlock    634\n",
      "BrkTil    146\n",
      "Slab       24\n",
      "Stone       6\n",
      "Wood        3\n",
      "Name: Foundation, dtype: int64\n",
      "\n",
      "BsmtQual属性的不同取值和出现的次数\n",
      "TA    649\n",
      "Gd    618\n",
      "Ex    121\n",
      "Fa     35\n",
      "Name: BsmtQual, dtype: int64\n",
      "\n",
      "BsmtCond属性的不同取值和出现的次数\n",
      "TA    1311\n",
      "Gd      65\n",
      "Fa      45\n",
      "Po       2\n",
      "Name: BsmtCond, dtype: int64\n",
      "\n",
      "BsmtExposure属性的不同取值和出现的次数\n",
      "No    953\n",
      "Av    221\n",
      "Gd    134\n",
      "Mn    114\n",
      "Name: BsmtExposure, dtype: int64\n",
      "\n",
      "BsmtFinType1属性的不同取值和出现的次数\n",
      "Unf    430\n",
      "GLQ    418\n",
      "ALQ    220\n",
      "BLQ    148\n",
      "Rec    133\n",
      "LwQ     74\n",
      "Name: BsmtFinType1, dtype: int64\n",
      "\n",
      "BsmtFinType2属性的不同取值和出现的次数\n",
      "Unf    1256\n",
      "Rec      54\n",
      "LwQ      46\n",
      "BLQ      33\n",
      "ALQ      19\n",
      "GLQ      14\n",
      "Name: BsmtFinType2, dtype: int64\n",
      "\n",
      "Heating属性的不同取值和出现的次数\n",
      "GasA     1428\n",
      "GasW       18\n",
      "Grav        7\n",
      "Wall        4\n",
      "OthW        2\n",
      "Floor       1\n",
      "Name: Heating, dtype: int64\n",
      "\n",
      "HeatingQC属性的不同取值和出现的次数\n",
      "Ex    741\n",
      "TA    428\n",
      "Gd    241\n",
      "Fa     49\n",
      "Po      1\n",
      "Name: HeatingQC, dtype: int64\n",
      "\n",
      "CentralAir属性的不同取值和出现的次数\n",
      "Y    1365\n",
      "N      95\n",
      "Name: CentralAir, dtype: int64\n",
      "\n",
      "Electrical属性的不同取值和出现的次数\n",
      "SBrkr    1334\n",
      "FuseA      94\n",
      "FuseF      27\n",
      "FuseP       3\n",
      "Mix         1\n",
      "Name: Electrical, dtype: int64\n",
      "\n",
      "KitchenQual属性的不同取值和出现的次数\n",
      "TA    735\n",
      "Gd    586\n",
      "Ex    100\n",
      "Fa     39\n",
      "Name: KitchenQual, dtype: int64\n",
      "\n",
      "Functional属性的不同取值和出现的次数\n",
      "Typ     1360\n",
      "Min2      34\n",
      "Min1      31\n",
      "Mod       15\n",
      "Maj1      14\n",
      "Maj2       5\n",
      "Sev        1\n",
      "Name: Functional, dtype: int64\n",
      "\n",
      "FireplaceQu属性的不同取值和出现的次数\n",
      "Gd    380\n",
      "TA    313\n",
      "Fa     33\n",
      "Ex     24\n",
      "Po     20\n",
      "Name: FireplaceQu, dtype: int64\n",
      "\n",
      "GarageType属性的不同取值和出现的次数\n",
      "Attchd     870\n",
      "Detchd     387\n",
      "BuiltIn     88\n",
      "Basment     19\n",
      "CarPort      9\n",
      "2Types       6\n",
      "Name: GarageType, dtype: int64\n",
      "\n",
      "GarageFinish属性的不同取值和出现的次数\n",
      "Unf    605\n",
      "RFn    422\n",
      "Fin    352\n",
      "Name: GarageFinish, dtype: int64\n",
      "\n",
      "GarageQual属性的不同取值和出现的次数\n",
      "TA    1311\n",
      "Fa      48\n",
      "Gd      14\n",
      "Ex       3\n",
      "Po       3\n",
      "Name: GarageQual, dtype: int64\n",
      "\n",
      "GarageCond属性的不同取值和出现的次数\n",
      "TA    1326\n",
      "Fa      35\n",
      "Gd       9\n",
      "Po       7\n",
      "Ex       2\n",
      "Name: GarageCond, dtype: int64\n",
      "\n",
      "PavedDrive属性的不同取值和出现的次数\n",
      "Y    1340\n",
      "N      90\n",
      "P      30\n",
      "Name: PavedDrive, dtype: int64\n",
      "\n",
      "PoolQC属性的不同取值和出现的次数\n",
      "Gd    3\n",
      "Ex    2\n",
      "Fa    2\n",
      "Name: PoolQC, dtype: int64\n",
      "\n",
      "Fence属性的不同取值和出现的次数\n",
      "MnPrv    157\n",
      "GdPrv     59\n",
      "GdWo      54\n",
      "MnWw      11\n",
      "Name: Fence, dtype: int64\n",
      "\n",
      "MiscFeature属性的不同取值和出现的次数\n",
      "Shed    49\n",
      "Othr     2\n",
      "Gar2     2\n",
      "TenC     1\n",
      "Name: MiscFeature, dtype: int64\n",
      "\n",
      "SaleType属性的不同取值和出现的次数\n",
      "WD       1267\n",
      "New       122\n",
      "COD        43\n",
      "ConLD       9\n",
      "ConLw       5\n",
      "ConLI       5\n",
      "CWD         4\n",
      "Oth         3\n",
      "Con         2\n",
      "Name: SaleType, dtype: int64\n",
      "\n",
      "SaleCondition属性的不同取值和出现的次数\n",
      "Normal     1198\n",
      "Partial     125\n",
      "Abnorml     101\n",
      "Family       20\n",
      "Alloca       12\n",
      "AdjLand       4\n",
      "Name: SaleCondition, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "#对类别型特征，观察其取值范围及直方图\n",
    "categorical_features = train_data.select_dtypes(include = [\"object\"]).columns\n",
    "for col in categorical_features:\n",
    "    print '\\n%s属性的不同取值和出现的次数'%col\n",
    "    print train_data[col].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 特征工程"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train_data.drop(['Id'], inplace = True, axis = 1)\n",
    "test_id = test_data['Id']\n",
    "test_data.drop(['Id'], inplace = True, axis = 1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 离群点检测"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZsAAAEWCAYAAACwtjr+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3Xu4XFWd5vHva7gqiQkQEEnaoEZa\nnBkRjhDF8YJ2SFAJ7UAL7ZjIoOlm1NFH+1EYZwyi9qCPI92MiEZhCN4gokiaBuMRvLQOl5xwj4g5\nCJjTocnBAIniI4q/+WOvgk1R93N2XXa9n+epp/Ze+7LWTurUr9baa62tiMDMzKxIz+h1AczMrPwc\nbMzMrHAONmZmVjgHGzMzK5yDjZmZFc7BxszMCudgY1ZF0g8lvbPOtqslrSgo39MkPSDpN5L2KSKP\nTkl6raSJ3PomSa/tYZFswOzS6wKYTYWke4F3RsT3u5FfRCwt4rySdgU+CyyKiFuLyKPN8gSwMCLG\na22PiJd0uUg24FyzMesP+wN7AJvaPVCZgfhbluQfuENqID6gZp2Q9C5J45K2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73tTzZG61U15iu59b0\n2gR8JKWX5vM6HS9PV2NmZoVzM5qZmRXOwcbMzArnYGNmZoVzsDEzs8I52JiZWeEcbMymgaT9JX1d\n0i/TlCXXSfrLGvstUG7G7lz6WZLe0EI+L5MU/TjzsVkjDjZmU5QGoX4H+HFEPD8iDicbxDivar+6\n00NFxEcj4vstZHcy8JP0XrMskvx3bX3HH0qzqTsaeCwivlBJiIj7IuL/SHqHpG9K+ifge/VOIOki\nSSdIWippbS79tenYSlA7AXgH2UjzPVL6AmXP/vk8cBMwX9LiVLu6KeW/V9r3o5I2SLpD0mo1mHDO\nbDo52JhN3UvIvuTreQWwIiKObuFco8CiNO0JwFuBS9PyUcA9EXE32Vxqx+aOO5hs2vqXAb8F/gfw\nhog4DBgje6YMwOci4uUR8e+APYE3tVAmsylzsDGbZpLOU/YEzg0paTQiqp9BVFNkU+t/F3hzanZ7\nI0/OqXUy2YSWpPd8U9p9kT0bBbIJPQ8BfpoeYbACeF7a9jplT8G8naxG9pL2r9CsfX7EgNnUbQL+\nU2UlIt4taV+yGgVkNY12XAq8m2zG4w0RsVPSjJTHcZI+Qja/1j6VCSCr8hBZgHvKfZ3U7PZ5srm4\ntkg6k2w+MrPCuWZjNnXXAntIOi2X9swpnO+HZI/+fhdPNqG9Abg1IuZHxIKIeB7ZIxiOr3H89cBR\nkl4IIOmZkl7Ek4HlwXQP54Qax5oVwsHGbIoim832eOA1ku6RdCPZY4A/XOeQgyVN5F4nVp3vceBK\nYGl6h6zJ7PKq83wL+Osa5Zkk60TwDUm3kQWfP4/suTlfIptp+DvAhupjzYriWZ/NzKxwrtmYmVnh\nHGzMzKxwDjZmZlY4BxszMyucg42ZmRXOwcbMzArnYGNmZoX7//KqxPBztvolAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xd0290f0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 离群点检测（outliers），参考该数据集的介绍papper：https://ww2.amstat.org/publications/jse/v19n3/decock.pdf\n",
    "plt.scatter(train_data.GrLivArea, train_data.SalePrice, c = \"blue\", marker = \"s\")\n",
    "plt.title(\"Looking for outliers\")\n",
    "plt.xlabel(\"GrLivArea\")\n",
    "plt.ylabel(\"SalePrice\")\n",
    "plt.show()\n",
    "\n",
    "#剔除离群点\n",
    "train_data = train_data[train_data.GrLivArea < 4000]\n",
    "temp = train_data.reindex()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1456, 80)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZsAAAEWCAYAAACwtjr+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3XvUXHV97/H3RwJySwyXgECgAYlW\n2nNUfCoBu7yghWCVoNUW65GUg80px0tb67JwPC0obY96XGg5IopiCQpyUySlYozgpbbcnqjcwTwK\nkkcQQgMkgpWL3/PH/g3sTOay57Jn9sx8XmvNemZ++/abncn+7t91KyIwMzMr07OGnQEzMxt/DjZm\nZlY6BxszMyudg42ZmZXOwcbMzErnYGNmZqVzsDGrI+nbkt7RZNmVkpaXdNwTJd0v6ReSdivjGN2S\n9CpJs7nPt0p61RCzZCNmzrAzYNYLSXcD74iIbw7ieBFxVBn7lbQtcDqwJCJuLOMYHeYngMURMdNo\neUT81oCzZCPOJRuzatgT2B64tdMNlRmJ/8uSfIM7oUbiB2rWDUl/KmlG0kZJqyTtnVt2mKQbJD2S\n/h7WZB97SbpJ0vvS56er2CT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47Yi4K627a0RslLQD2fQlryQb3f/vZKWUzcDVwI0R8a4U\nqD4VEd+TtB/ZFPUvTPv6JtlMAfcDl0bEf03p5wK7A8si4ilJ/wDcFhFfTKWh68lmBY9G+e7/2bNJ\n5qK1WQ8knUk2RdDjZBNfflLSi4GngOfnVr2+FmiS9+TaefYlmzfrucB3ImJj2vcluX28Fjgoq8UD\nYJ6kucCOwIHA9yIiJD0p6bcjovZkxksi4qn0/giySU/flz5vD+xHNqlis3yb9YWDjVlnbiWrtgIg\nIt6p7LG608BfkpUuXkRWRf2fue0erb1JJZ3Xkj2o7DFJ3ya78Deayr3mWWn9X+YTJR1PNjfbXSkQ\nzSOrSvvf9cdN+/+DiLizbh+ntsi3WV+4zcasM1cD20s6MZe2Y/r7HOC+iPg18Hayx/828hzgoRRo\nfpPsEbyQVWu9Ms2uO4dcUAO+Abyr9iGVQiB7iuLSeGYW31qHhUZWA+9OnRyQ9JIO823WNQcbsw5E\n1sh5DFlQuEvS9cBKsinmPwUsl3QtWVXUo01283VgjqSbgNOAa9O+fwb8A9mTVb9J9jiAR9I27wGm\nJN0k6Tbgz5Q9iXW/2vZpH3cBmyQd0uC4pwHbAjdJuiV9poN8m3XNHQTMKkTSzhHxi1SyuQz4fERc\nNux8mfXKJRuzajlV0g/Jnj9zF9mYHrOR55KNmZmVziUbMzMrnYONmZmVzsHGzMxK52BjZmalc7Ax\nM7PS/X8cM4RUPkun0QAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xd22d048>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(train_data.GarageArea, train_data.SalePrice, c = \"blue\", marker = \"s\")\n",
    "plt.title(\"Looking for outliers\")\n",
    "plt.xlabel(\"GarageArea\")\n",
    "plt.ylabel(\"SalePrice\")\n",
    "plt.show()\n",
    "\n",
    "#剔除离群点\n",
    "train_data = train_data[train_data.GarageArea < 1200]\n",
    "temp = train_data.reindex()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1452, 80)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 缺失值处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 有些特征，用median/mean or most common value 填充没有意义\n",
    "# 因为特征工程对训练集和测试都需要进行，因此我们定义成函数，将数据集以参数形式传递\n",
    "def process_missvalue_by_meaning (df):\n",
    "    # Alley : data description says NA means \"no alley access\"\n",
    "    df.loc[:, \"Alley\"] = df.loc[:, \"Alley\"].fillna(\"None\")\n",
    "\n",
    "    # BedroomAbvGr : NA most likely means 0\n",
    "    df.loc[:, \"BedroomAbvGr\"] = df.loc[:, \"BedroomAbvGr\"].fillna(0)\n",
    "\n",
    "    # BsmtQual etc : data description says NA for basement features is \"no basement\"\n",
    "    df.loc[:, \"BsmtQual\"] = df.loc[:, \"BsmtQual\"].fillna(\"No\")\n",
    "    df.loc[:, \"BsmtCond\"] = df.loc[:, \"BsmtCond\"].fillna(\"No\")\n",
    "    df.loc[:, \"BsmtExposure\"] = df.loc[:, \"BsmtExposure\"].fillna(\"No\")\n",
    "    df.loc[:, \"BsmtFinType1\"] = df.loc[:, \"BsmtFinType1\"].fillna(\"No\")\n",
    "    df.loc[:, \"BsmtFinType2\"] = df.loc[:, \"BsmtFinType2\"].fillna(\"No\")\n",
    "    df.loc[:, \"BsmtFullBath\"] = df.loc[:, \"BsmtFullBath\"].fillna(0)\n",
    "    df.loc[:, \"BsmtHalfBath\"] = df.loc[:, \"BsmtHalfBath\"].fillna(0)\n",
    "    df.loc[:, \"BsmtUnfSF\"] = df.loc[:, \"BsmtUnfSF\"].fillna(0)\n",
    "\n",
    "    # CentralAir : NA most likely means No\n",
    "    df.loc[:, \"CentralAir\"] = df.loc[:, \"CentralAir\"].fillna(\"N\")\n",
    "\n",
    "    # Condition : NA most likely means Normal，靠近主干道或铁路\n",
    "    df.loc[:, \"Condition1\"] = df.loc[:, \"Condition1\"].fillna(\"Norm\")\n",
    "    df.loc[:, \"Condition2\"] = df.loc[:, \"Condition2\"].fillna(\"Norm\")\n",
    "\n",
    "    # EnclosedPorch : NA most likely means no enclosed porch\n",
    "    df.loc[:, \"EnclosedPorch\"] = df.loc[:, \"EnclosedPorch\"].fillna(0)\n",
    "\n",
    "    # External stuff : NA most likely means average\n",
    "    df.loc[:, \"ExterCond\"] = df.loc[:, \"ExterCond\"].fillna(\"TA\")\n",
    "    df.loc[:, \"ExterQual\"] = df.loc[:, \"ExterQual\"].fillna(\"TA\")\n",
    "\n",
    "    # Fence : data description says NA means \"no fence\"\n",
    "    df.loc[:, \"Fence\"] = df.loc[:, \"Fence\"].fillna(\"No\")\n",
    "\n",
    "    # FireplaceQu : data description says NA means \"no fireplace\"\n",
    "    df.loc[:, \"FireplaceQu\"] = df.loc[:, \"FireplaceQu\"].fillna(\"No\")\n",
    "    df.loc[:, \"Fireplaces\"] = df.loc[:, \"Fireplaces\"].fillna(0)\n",
    "\n",
    "    # Functional : data description says NA means typical，家用（Home）功能性评级\n",
    "    df.loc[:, \"Functional\"] = df.loc[:, \"Functional\"].fillna(\"Typ\")\n",
    "\n",
    "    # GarageType etc : data description says NA for garage features is \"no garage\"\n",
    "    df.loc[:, \"GarageType\"] = df.loc[:, \"GarageType\"].fillna(\"No\")\n",
    "    df.loc[:, \"GarageFinish\"] = df.loc[:, \"GarageFinish\"].fillna(\"No\")\n",
    "    df.loc[:, \"GarageQual\"] = df.loc[:, \"GarageQual\"].fillna(\"No\")\n",
    "    df.loc[:, \"GarageCond\"] = df.loc[:, \"GarageCond\"].fillna(\"No\")\n",
    "    df.loc[:, \"GarageArea\"] = df.loc[:, \"GarageArea\"].fillna(0)\n",
    "    df.loc[:, \"GarageCars\"] = df.loc[:, \"GarageCars\"].fillna(0)\n",
    "\n",
    "    # HalfBath : NA most likely means no half baths above grade\n",
    "    df.loc[:, \"HalfBath\"] = df.loc[:, \"HalfBath\"].fillna(0)\n",
    "\n",
    "    # HeatingQC : NA most likely means typical\n",
    "    df.loc[:, \"HeatingQC\"] = df.loc[:, \"HeatingQC\"].fillna(\"TA\")\n",
    "\n",
    "    # KitchenAbvGr : NA most likely means 0\n",
    "    df.loc[:, \"KitchenAbvGr\"] = df.loc[:, \"KitchenAbvGr\"].fillna(0)\n",
    "\n",
    "    # KitchenQual : NA most likely means typical\n",
    "    df.loc[:, \"KitchenQual\"] = df.loc[:, \"KitchenQual\"].fillna(\"TA\")\n",
    "\n",
    "    # LotFrontage : NA most likely means no lot frontage\n",
    "    df.loc[:, \"LotFrontage\"] = df.loc[:, \"LotFrontage\"].fillna(0)\n",
    "\n",
    "    # LotShape : NA most likely means regular\n",
    "    df.loc[:, \"LotShape\"] = df.loc[:, \"LotShape\"].fillna(\"Reg\")\n",
    "\n",
    "    # MasVnrType : NA most likely means no veneer，表层砌体（Masonry veneer）类型\n",
    "    df.loc[:, \"MasVnrType\"] = df.loc[:, \"MasVnrType\"].fillna(\"None\")\n",
    "    df.loc[:, \"MasVnrArea\"] = df.loc[:, \"MasVnrArea\"].fillna(0)\n",
    "\n",
    "    # MiscFeature : data description says NA means \"no misc feature\"\n",
    "    df.loc[:, \"MiscFeature\"] = df.loc[:, \"MiscFeature\"].fillna(\"No\")\n",
    "    df.loc[:, \"MiscVal\"] = df.loc[:, \"MiscVal\"].fillna(0)\n",
    "\n",
    "    # OpenPorchSF : NA most likely means no open porch\n",
    "    df.loc[:, \"OpenPorchSF\"] = df.loc[:, \"OpenPorchSF\"].fillna(0)\n",
    "\n",
    "    # PavedDrive : NA most likely means not paved\n",
    "    df.loc[:, \"PavedDrive\"] = df.loc[:, \"PavedDrive\"].fillna(\"N\")\n",
    "\n",
    "    # PoolQC : data description says NA means \"no pool\"\n",
    "    df.loc[:, \"PoolQC\"] = df.loc[:, \"PoolQC\"].fillna(\"No\")\n",
    "    df.loc[:, \"PoolArea\"] = df.loc[:, \"PoolArea\"].fillna(0)\n",
    "\n",
    "    # SaleCondition : NA most likely means normal sale\n",
    "    df.loc[:, \"SaleCondition\"] = df.loc[:, \"SaleCondition\"].fillna(\"Normal\")\n",
    "\n",
    "    # ScreenPorch : NA most likely means no screen porch，观景门廊\n",
    "    df.loc[:, \"ScreenPorch\"] = df.loc[:, \"ScreenPorch\"].fillna(0)\n",
    "\n",
    "    # TotRmsAbvGrd : NA most likely means 0\n",
    "    df.loc[:, \"TotRmsAbvGrd\"] = df.loc[:, \"TotRmsAbvGrd\"].fillna(0)\n",
    "\n",
    "    # Utilities : NA most likely means all public utilities\n",
    "    df.loc[:, \"Utilities\"] = df.loc[:, \"Utilities\"].fillna(\"AllPub\")\n",
    "\n",
    "    # WoodDeckSF : NA most likely means no wood deck\n",
    "    df.loc[:, \"WoodDeckSF\"] = df.loc[:, \"WoodDeckSF\"].fillna(0)\n",
    "    \n",
    "    return df \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MSSubClass</th>\n",
       "      <th>MSZoning</th>\n",
       "      <th>LotFrontage</th>\n",
       "      <th>LotArea</th>\n",
       "      <th>Street</th>\n",
       "      <th>Alley</th>\n",
       "      <th>LotShape</th>\n",
       "      <th>LandContour</th>\n",
       "      <th>Utilities</th>\n",
       "      <th>LotConfig</th>\n",
       "      <th>...</th>\n",
       "      <th>PoolArea</th>\n",
       "      <th>PoolQC</th>\n",
       "      <th>Fence</th>\n",
       "      <th>MiscFeature</th>\n",
       "      <th>MiscVal</th>\n",
       "      <th>MoSold</th>\n",
       "      <th>YrSold</th>\n",
       "      <th>SaleType</th>\n",
       "      <th>SaleCondition</th>\n",
       "      <th>SalePrice</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>60</td>\n",
       "      <td>RL</td>\n",
       "      <td>65.000</td>\n",
       "      <td>8450</td>\n",
       "      <td>Pave</td>\n",
       "      <td>None</td>\n",
       "      <td>Reg</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>Inside</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2008</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>208500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20</td>\n",
       "      <td>RL</td>\n",
       "      <td>80.000</td>\n",
       "      <td>9600</td>\n",
       "      <td>Pave</td>\n",
       "      <td>None</td>\n",
       "      <td>Reg</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>FR2</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>2007</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>181500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>60</td>\n",
       "      <td>RL</td>\n",
       "      <td>68.000</td>\n",
       "      <td>11250</td>\n",
       "      <td>Pave</td>\n",
       "      <td>None</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>Inside</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>2008</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>223500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>70</td>\n",
       "      <td>RL</td>\n",
       "      <td>60.000</td>\n",
       "      <td>9550</td>\n",
       "      <td>Pave</td>\n",
       "      <td>None</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>Corner</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2006</td>\n",
       "      <td>WD</td>\n",
       "      <td>Abnorml</td>\n",
       "      <td>140000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>60</td>\n",
       "      <td>RL</td>\n",
       "      <td>84.000</td>\n",
       "      <td>14260</td>\n",
       "      <td>Pave</td>\n",
       "      <td>None</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>FR2</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>0</td>\n",
       "      <td>12</td>\n",
       "      <td>2008</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>250000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 80 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   MSSubClass MSZoning  LotFrontage  LotArea Street Alley LotShape  \\\n",
       "0          60       RL       65.000     8450   Pave  None      Reg   \n",
       "1          20       RL       80.000     9600   Pave  None      Reg   \n",
       "2          60       RL       68.000    11250   Pave  None      IR1   \n",
       "3          70       RL       60.000     9550   Pave  None      IR1   \n",
       "4          60       RL       84.000    14260   Pave  None      IR1   \n",
       "\n",
       "  LandContour Utilities LotConfig    ...     PoolArea PoolQC Fence  \\\n",
       "0         Lvl    AllPub    Inside    ...            0     No    No   \n",
       "1         Lvl    AllPub       FR2    ...            0     No    No   \n",
       "2         Lvl    AllPub    Inside    ...            0     No    No   \n",
       "3         Lvl    AllPub    Corner    ...            0     No    No   \n",
       "4         Lvl    AllPub       FR2    ...            0     No    No   \n",
       "\n",
       "  MiscFeature MiscVal MoSold  YrSold  SaleType  SaleCondition  SalePrice  \n",
       "0          No       0      2    2008        WD         Normal     208500  \n",
       "1          No       0      5    2007        WD         Normal     181500  \n",
       "2          No       0      9    2008        WD         Normal     223500  \n",
       "3          No       0      2    2006        WD        Abnorml     140000  \n",
       "4          No       0     12    2008        WD         Normal     250000  \n",
       "\n",
       "[5 rows x 80 columns]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data = process_missvalue_by_meaning(train_data)\n",
    "test_data = process_missvalue_by_meaning(test_data)\n",
    "train_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Some numerical features are actually really categories\n",
    "# MSSubClass：建筑类\n",
    "#MoSold：销售月份\n",
    "\n",
    "def numberical2cat(df):\n",
    "    df.replace({\"MSSubClass\" : {20 : \"SC20\", 30 : \"SC30\", 40 : \"SC40\", 45 : \"SC45\", \n",
    "                                       50 : \"SC50\", 60 : \"SC60\", 70 : \"SC70\", 75 : \"SC75\", \n",
    "                                       80 : \"SC80\", 85 : \"SC85\", 90 : \"SC90\", 120 : \"SC120\", \n",
    "                                       150 : \"SC150\", 160 : \"SC160\", 180 : \"SC180\", 190 : \"SC190\"},\n",
    "                       \"MoSold\" : {1 : \"Jan\", 2 : \"Feb\", 3 : \"Mar\", 4 : \"Apr\", 5 : \"May\", 6 : \"Jun\",\n",
    "                                   7 : \"Jul\", 8 : \"Aug\", 9 : \"Sep\", 10 : \"Oct\", 11 : \"Nov\", 12 : \"Dec\"}\n",
    "                      }, inplace = True)\n",
    "\n",
    "    return df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MSSubClass</th>\n",
       "      <th>MSZoning</th>\n",
       "      <th>LotFrontage</th>\n",
       "      <th>LotArea</th>\n",
       "      <th>Street</th>\n",
       "      <th>Alley</th>\n",
       "      <th>LotShape</th>\n",
       "      <th>LandContour</th>\n",
       "      <th>Utilities</th>\n",
       "      <th>LotConfig</th>\n",
       "      <th>...</th>\n",
       "      <th>PoolArea</th>\n",
       "      <th>PoolQC</th>\n",
       "      <th>Fence</th>\n",
       "      <th>MiscFeature</th>\n",
       "      <th>MiscVal</th>\n",
       "      <th>MoSold</th>\n",
       "      <th>YrSold</th>\n",
       "      <th>SaleType</th>\n",
       "      <th>SaleCondition</th>\n",
       "      <th>SalePrice</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>SC60</td>\n",
       "      <td>RL</td>\n",
       "      <td>65.000</td>\n",
       "      <td>8450</td>\n",
       "      <td>Pave</td>\n",
       "      <td>None</td>\n",
       "      <td>Reg</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>Inside</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>0</td>\n",
       "      <td>Feb</td>\n",
       "      <td>2008</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>208500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>SC20</td>\n",
       "      <td>RL</td>\n",
       "      <td>80.000</td>\n",
       "      <td>9600</td>\n",
       "      <td>Pave</td>\n",
       "      <td>None</td>\n",
       "      <td>Reg</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>FR2</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>0</td>\n",
       "      <td>May</td>\n",
       "      <td>2007</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>181500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>SC60</td>\n",
       "      <td>RL</td>\n",
       "      <td>68.000</td>\n",
       "      <td>11250</td>\n",
       "      <td>Pave</td>\n",
       "      <td>None</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>Inside</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>0</td>\n",
       "      <td>Sep</td>\n",
       "      <td>2008</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>223500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>SC70</td>\n",
       "      <td>RL</td>\n",
       "      <td>60.000</td>\n",
       "      <td>9550</td>\n",
       "      <td>Pave</td>\n",
       "      <td>None</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>Corner</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>0</td>\n",
       "      <td>Feb</td>\n",
       "      <td>2006</td>\n",
       "      <td>WD</td>\n",
       "      <td>Abnorml</td>\n",
       "      <td>140000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>SC60</td>\n",
       "      <td>RL</td>\n",
       "      <td>84.000</td>\n",
       "      <td>14260</td>\n",
       "      <td>Pave</td>\n",
       "      <td>None</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>FR2</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>0</td>\n",
       "      <td>Dec</td>\n",
       "      <td>2008</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>250000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 80 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "  MSSubClass MSZoning  LotFrontage  LotArea Street Alley LotShape LandContour  \\\n",
       "0       SC60       RL       65.000     8450   Pave  None      Reg         Lvl   \n",
       "1       SC20       RL       80.000     9600   Pave  None      Reg         Lvl   \n",
       "2       SC60       RL       68.000    11250   Pave  None      IR1         Lvl   \n",
       "3       SC70       RL       60.000     9550   Pave  None      IR1         Lvl   \n",
       "4       SC60       RL       84.000    14260   Pave  None      IR1         Lvl   \n",
       "\n",
       "  Utilities LotConfig    ...     PoolArea PoolQC Fence MiscFeature MiscVal  \\\n",
       "0    AllPub    Inside    ...            0     No    No          No       0   \n",
       "1    AllPub       FR2    ...            0     No    No          No       0   \n",
       "2    AllPub    Inside    ...            0     No    No          No       0   \n",
       "3    AllPub    Corner    ...            0     No    No          No       0   \n",
       "4    AllPub       FR2    ...            0     No    No          No       0   \n",
       "\n",
       "  MoSold  YrSold  SaleType  SaleCondition  SalePrice  \n",
       "0    Feb    2008        WD         Normal     208500  \n",
       "1    May    2007        WD         Normal     181500  \n",
       "2    Sep    2008        WD         Normal     223500  \n",
       "3    Feb    2006        WD        Abnorml     140000  \n",
       "4    Dec    2008        WD         Normal     250000  \n",
       "\n",
       "[5 rows x 80 columns]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data = numberical2cat(train_data)\n",
    "test_data = numberical2cat(test_data)\n",
    "train_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Encode some categorical features as ordered numbers when there is information in the order\n",
    "def cat2numberical(df):\n",
    "    df.replace({\"Alley\" : {\"None\":0, \"Grvl\" : 1, \"Pave\" : 2},\n",
    "                \"BsmtCond\" : {\"No\" : 0, \"Po\" : 1, \"Fa\" : 2, \"TA\" : 3, \"Gd\" : 4, \"Ex\" : 5},\n",
    "                \"BsmtExposure\" : {\"No\" : 0, \"Mn\" : 1, \"Av\": 2, \"Gd\" : 3},\n",
    "                \"BsmtFinType1\" : {\"No\" : 0, \"Unf\" : 1, \"LwQ\": 2, \"Rec\" : 3, \"BLQ\" : 4, \n",
    "                                         \"ALQ\" : 5, \"GLQ\" : 6},\n",
    "                \"BsmtFinType2\" : {\"No\" : 0, \"Unf\" : 1, \"LwQ\": 2, \"Rec\" : 3, \"BLQ\" : 4, \n",
    "                                         \"ALQ\" : 5, \"GLQ\" : 6},\n",
    "                \"BsmtQual\" : {\"No\" : 0, \"Po\" : 1, \"Fa\" : 2, \"TA\": 3, \"Gd\" : 4, \"Ex\" : 5},\n",
    "                \"ExterCond\" : {\"Po\" : 1, \"Fa\" : 2, \"TA\": 3, \"Gd\": 4, \"Ex\" : 5},\n",
    "                \"ExterQual\" : {\"Po\" : 1, \"Fa\" : 2, \"TA\": 3, \"Gd\": 4, \"Ex\" : 5},\n",
    "                \"FireplaceQu\" : {\"No\" : 0, \"Po\" : 1, \"Fa\" : 2, \"TA\" : 3, \"Gd\" : 4, \"Ex\" : 5},\n",
    "                \"Functional\" : {\"Sal\" : 1, \"Sev\" : 2, \"Maj2\" : 3, \"Maj1\" : 4, \"Mod\": 5, \n",
    "                                       \"Min2\" : 6, \"Min1\" : 7, \"Typ\" : 8},\n",
    "                \"GarageCond\" : {\"No\" : 0, \"Po\" : 1, \"Fa\" : 2, \"TA\" : 3, \"Gd\" : 4, \"Ex\" : 5},\n",
    "                \"GarageQual\" : {\"No\" : 0, \"Po\" : 1, \"Fa\" : 2, \"TA\" : 3, \"Gd\" : 4, \"Ex\" : 5},\n",
    "                \"HeatingQC\" : {\"Po\" : 1, \"Fa\" : 2, \"TA\" : 3, \"Gd\" : 4, \"Ex\" : 5},\n",
    "                \"KitchenQual\" : {\"Po\" : 1, \"Fa\" : 2, \"TA\" : 3, \"Gd\" : 4, \"Ex\" : 5},\n",
    "                \"LandSlope\" : {\"Sev\" : 1, \"Mod\" : 2, \"Gtl\" : 3},\n",
    "                \"LotShape\" : {\"IR3\" : 1, \"IR2\" : 2, \"IR1\" : 3, \"Reg\" : 4},\n",
    "                \"PavedDrive\" : {\"N\" : 0, \"P\" : 1, \"Y\" : 2},\n",
    "                \"PoolQC\" : {\"No\" : 0, \"Fa\" : 1, \"TA\" : 2, \"Gd\" : 3, \"Ex\" : 4},\n",
    "                \"Street\" : {\"Grvl\" : 1, \"Pave\" : 2},\n",
    "                \"Utilities\" : {\"ELO\" : 1, \"NoSeWa\" : 2, \"NoSewr\" : 3, \"AllPub\" : 4}},\n",
    "                       inplace = True\n",
    "                     )\n",
    "    return df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train_data = cat2numberical(train_data)\n",
    "test_data = cat2numberical(test_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 1452 entries, 0 to 1459\n",
      "Data columns (total 80 columns):\n",
      "MSSubClass       1452 non-null object\n",
      "MSZoning         1452 non-null object\n",
      "LotFrontage      1452 non-null float64\n",
      "LotArea          1452 non-null int64\n",
      "Street           1452 non-null int64\n",
      "Alley            1452 non-null int64\n",
      "LotShape         1452 non-null int64\n",
      "LandContour      1452 non-null object\n",
      "Utilities        1452 non-null int64\n",
      "LotConfig        1452 non-null object\n",
      "LandSlope        1452 non-null int64\n",
      "Neighborhood     1452 non-null object\n",
      "Condition1       1452 non-null object\n",
      "Condition2       1452 non-null object\n",
      "BldgType         1452 non-null object\n",
      "HouseStyle       1452 non-null object\n",
      "OverallQual      1452 non-null int64\n",
      "OverallCond      1452 non-null int64\n",
      "YearBuilt        1452 non-null int64\n",
      "YearRemodAdd     1452 non-null int64\n",
      "RoofStyle        1452 non-null object\n",
      "RoofMatl         1452 non-null object\n",
      "Exterior1st      1452 non-null object\n",
      "Exterior2nd      1452 non-null object\n",
      "MasVnrType       1452 non-null object\n",
      "MasVnrArea       1452 non-null float64\n",
      "ExterQual        1452 non-null int64\n",
      "ExterCond        1452 non-null int64\n",
      "Foundation       1452 non-null object\n",
      "BsmtQual         1452 non-null int64\n",
      "BsmtCond         1452 non-null int64\n",
      "BsmtExposure     1452 non-null int64\n",
      "BsmtFinType1     1452 non-null int64\n",
      "BsmtFinSF1       1452 non-null int64\n",
      "BsmtFinType2     1452 non-null int64\n",
      "BsmtFinSF2       1452 non-null int64\n",
      "BsmtUnfSF        1452 non-null int64\n",
      "TotalBsmtSF      1452 non-null int64\n",
      "Heating          1452 non-null object\n",
      "HeatingQC        1452 non-null int64\n",
      "CentralAir       1452 non-null object\n",
      "Electrical       1451 non-null object\n",
      "1stFlrSF         1452 non-null int64\n",
      "2ndFlrSF         1452 non-null int64\n",
      "LowQualFinSF     1452 non-null int64\n",
      "GrLivArea        1452 non-null int64\n",
      "BsmtFullBath     1452 non-null int64\n",
      "BsmtHalfBath     1452 non-null int64\n",
      "FullBath         1452 non-null int64\n",
      "HalfBath         1452 non-null int64\n",
      "BedroomAbvGr     1452 non-null int64\n",
      "KitchenAbvGr     1452 non-null int64\n",
      "KitchenQual      1452 non-null int64\n",
      "TotRmsAbvGrd     1452 non-null int64\n",
      "Functional       1452 non-null int64\n",
      "Fireplaces       1452 non-null int64\n",
      "FireplaceQu      1452 non-null int64\n",
      "GarageType       1452 non-null object\n",
      "GarageYrBlt      1371 non-null float64\n",
      "GarageFinish     1452 non-null object\n",
      "GarageCars       1452 non-null int64\n",
      "GarageArea       1452 non-null int64\n",
      "GarageQual       1452 non-null int64\n",
      "GarageCond       1452 non-null int64\n",
      "PavedDrive       1452 non-null int64\n",
      "WoodDeckSF       1452 non-null int64\n",
      "OpenPorchSF      1452 non-null int64\n",
      "EnclosedPorch    1452 non-null int64\n",
      "3SsnPorch        1452 non-null int64\n",
      "ScreenPorch      1452 non-null int64\n",
      "PoolArea         1452 non-null int64\n",
      "PoolQC           1452 non-null int64\n",
      "Fence            1452 non-null object\n",
      "MiscFeature      1452 non-null object\n",
      "MiscVal          1452 non-null int64\n",
      "MoSold           1452 non-null object\n",
      "YrSold           1452 non-null int64\n",
      "SaleType         1452 non-null object\n",
      "SaleCondition    1452 non-null object\n",
      "SalePrice        1452 non-null int64\n",
      "dtypes: float64(3), int64(52), object(25)\n",
      "memory usage: 918.8+ KB\n"
     ]
    }
   ],
   "source": [
    "train_data.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Create new features\n",
    "# 1* Simplifications of existing features\n",
    "# 合并类别\n",
    "def simplify(df):\n",
    "    df[\"SimplOverallQual\"] = df.OverallQual.replace({1 : 1, 2 : 1, 3 : 1, # bad\n",
    "                                                    4 : 2, 5 : 2, 6 : 2, # average\n",
    "                                                    7 : 3, 8 : 3, 9 : 3, 10 : 3 # good\n",
    "                                                    }, inplace = True)\n",
    "    df[\"SimplOverallCond\"] = df.OverallCond.replace({1 : 1, 2 : 1, 3 : 1, # bad\n",
    "                                                    4 : 2, 5 : 2, 6 : 2, # average\n",
    "                                                    7 : 3, 8 : 3, 9 : 3, 10 : 3 # good\n",
    "                                                    },inplace = True)\n",
    "    df[\"SimplPoolQC\"] = df.PoolQC.replace({1 : 1, 2 : 1, # average\n",
    "                                           3 : 2, 4 : 2 # good\n",
    "                                          },inplace = True)\n",
    "    df[\"SimplGarageCond\"] = df.GarageCond.replace({1 : 1, # bad\n",
    "                                                2 : 1, 3 : 1, # average\n",
    "                                                4 : 2, 5 : 2 # good\n",
    "                                                        },inplace = True)\n",
    "    df[\"SimplGarageQual\"] = df.GarageQual.replace({1 : 1, # bad\n",
    "                                                    2 : 1, 3 : 1, # average\n",
    "                                                    4 : 2, 5 : 2 # good\n",
    "                                                    },inplace = True)\n",
    "    df[\"SimplFireplaceQu\"] = df.FireplaceQu.replace({1 : 1, # bad\n",
    "                                                           2 : 1, 3 : 1, # average\n",
    "                                                           4 : 2, 5 : 2 # good\n",
    "                                                          },inplace = True)\n",
    "    df[\"SimplFireplaceQu\"] = df.FireplaceQu.replace({1 : 1, # bad\n",
    "                                                           2 : 1, 3 : 1, # average\n",
    "                                                           4 : 2, 5 : 2 # good\n",
    "                                                          },inplace = True)\n",
    "    df[\"SimplFunctional\"] = df.Functional.replace({1 : 1, 2 : 1, # bad\n",
    "                                                         3 : 2, 4 : 2, # major\n",
    "                                                         5 : 3, 6 : 3, 7 : 3, # minor\n",
    "                                                         8 : 4 # typical\n",
    "                                                        },inplace = True)\n",
    "    df[\"SimplKitchenQual\"] = df.KitchenQual.replace({1 : 1, # bad\n",
    "                                                           2 : 1, 3 : 1, # average\n",
    "                                                           4 : 2, 5 : 2 # good\n",
    "                                                          },inplace = True)\n",
    "    df[\"SimplHeatingQC\"] = df.HeatingQC.replace({1 : 1, # bad\n",
    "                                                       2 : 1, 3 : 1, # average\n",
    "                                                       4 : 2, 5 : 2 # good\n",
    "                                                      },inplace = True)\n",
    "    df[\"SimplBsmtFinType1\"] = df.BsmtFinType1.replace({1 : 1, # unfinished\n",
    "                                                             2 : 1, 3 : 1, # rec room\n",
    "                                                             4 : 2, 5 : 2, 6 : 2 # living quarters\n",
    "                                                            },inplace = True)\n",
    "    df[\"SimplBsmtFinType2\"] = df.BsmtFinType2.replace({1 : 1, # unfinished\n",
    "                                                             2 : 1, 3 : 1, # rec room\n",
    "                                                             4 : 2, 5 : 2, 6 : 2 # living quarters\n",
    "                                                            },inplace = True)\n",
    "    df[\"SimplBsmtCond\"] = df.BsmtCond.replace({1 : 1, # bad\n",
    "                                                     2 : 1, 3 : 1, # average\n",
    "                                                     4 : 2, 5 : 2 # good\n",
    "                                                    },inplace = True)\n",
    "    df[\"SimplBsmtQual\"] = df.BsmtQual.replace({1 : 1, # bad\n",
    "                                                     2 : 1, 3 : 1, # average\n",
    "                                                     4 : 2, 5 : 2 # good\n",
    "                                                    },inplace = True)\n",
    "    df[\"SimplExterCond\"] = df.ExterCond.replace({1 : 1, # bad\n",
    "                                                       2 : 1, 3 : 1, # average\n",
    "                                                       4 : 2, 5 : 2 # good\n",
    "                                                      },inplace = True)\n",
    "    df[\"SimplExterQual\"] = df.ExterQual.replace({1 : 1, # bad\n",
    "                                                       2 : 1, 3 : 1, # average\n",
    "                                                       4 : 2, 5 : 2 # good\n",
    "                                                      },inplace = True)\n",
    "    return df\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train_data = simplify(train_data)\n",
    "test_data = simplify(test_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 2* Combinations of existing features\n",
    "def Combine(df):\n",
    "    # Overall quality of the house\n",
    "    df[\"OverallGrade\"] = df[\"OverallQual\"] * df[\"OverallCond\"]\n",
    "    # Overall quality of the garage\n",
    "    df[\"GarageGrade\"] = df[\"GarageQual\"] * df[\"GarageCond\"]\n",
    "    # Overall quality of the exterior\n",
    "    df[\"ExterGrade\"] = df[\"ExterQual\"] * df[\"ExterCond\"]\n",
    "    # Overall kitchen score\n",
    "    df[\"KitchenScore\"] = df[\"KitchenAbvGr\"] * df[\"KitchenQual\"]\n",
    "    # Overall fireplace score\n",
    "    df[\"FireplaceScore\"] = df[\"Fireplaces\"] * df[\"FireplaceQu\"]\n",
    "    # Overall garage score\n",
    "    df[\"GarageScore\"] = df[\"GarageArea\"] * df[\"GarageQual\"]\n",
    "    # Overall pool score\n",
    "    df[\"PoolScore\"] = df[\"PoolArea\"] * df[\"PoolQC\"]\n",
    "    # Simplified overall quality of the house\n",
    "    df[\"SimplOverallGrade\"] = df[\"SimplOverallQual\"] * df[\"SimplOverallCond\"]\n",
    "    # Simplified overall quality of the exterior\n",
    "    df[\"SimplExterGrade\"] = df[\"SimplExterQual\"] * df[\"SimplExterCond\"]\n",
    "    # Simplified overall pool score\n",
    "    df[\"SimplPoolScore\"] = df[\"PoolArea\"] * df[\"SimplPoolQC\"]\n",
    "    # Simplified overall garage score\n",
    "    df[\"SimplGarageScore\"] = df[\"GarageArea\"] * df[\"SimplGarageQual\"]\n",
    "    # Simplified overall fireplace score\n",
    "    df[\"SimplFireplaceScore\"] = df[\"Fireplaces\"] * df[\"SimplFireplaceQu\"]\n",
    "    # Simplified overall kitchen score\n",
    "    df[\"SimplKitchenScore\"] = df[\"KitchenAbvGr\"] * df[\"SimplKitchenQual\"]\n",
    "    # Total number of bathrooms\n",
    "    df[\"TotalBath\"] = df[\"BsmtFullBath\"] + (0.5 * df[\"BsmtHalfBath\"]) + \\\n",
    "    df[\"FullBath\"] + (0.5 * df[\"HalfBath\"])\n",
    "    # Total SF for house (incl. basement)\n",
    "    df[\"AllSF\"] = df[\"GrLivArea\"] + df[\"TotalBsmtSF\"]\n",
    "    # Total SF for 1st + 2nd floors\n",
    "    df[\"AllFlrsSF\"] = df[\"1stFlrSF\"] + df[\"2ndFlrSF\"]\n",
    "    # Total SF for porch\n",
    "    df[\"AllPorchSF\"] = df[\"OpenPorchSF\"] + df[\"EnclosedPorch\"] + \\\n",
    "    df[\"3SsnPorch\"] + df[\"ScreenPorch\"]\n",
    "    # Has masonry veneer or not\n",
    "    df[\"HasMasVnr\"] = df.MasVnrType.replace({\"BrkCmn\" : 1, \"BrkFace\" : 1, \"CBlock\" : 1, \n",
    "                                                   \"Stone\" : 1, \"None\" : 0})\n",
    "    # House completed before sale or not\n",
    "    df[\"BoughtOffPlan\"] = df.SaleCondition.replace({\"Abnorml\" : 0, \"Alloca\" : 0, \"AdjLand\" : 0, \n",
    "                                                          \"Family\" : 0, \"Normal\" : 0, \"Partial\" : 1})\n",
    "    \n",
    "    return df\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#对训练集和测试集分别进行编码\n",
    "train_data = Combine(train_data)\n",
    "test_data = Combine(test_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Find most important features relative to target\n",
      "0.623677653283\n"
     ]
    }
   ],
   "source": [
    "# Find most important features relative to target\n",
    "print(\"Find most important features relative to target\")\n",
    "corr = train_data.corr()\n",
    "corr.sort_values([\"SalePrice\"], ascending = False, inplace = True)\n",
    "#print(corr.SalePrice)\n",
    "\n",
    "threshold = corr.SalePrice.iloc[11]  #the first one is SalePrice itself,from 1-11\n",
    "print threshold\n",
    "top10_cols = (corr.SalePrice[corr['SalePrice']>threshold]).axes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Create new features\n",
    "# 3* Polynomials on the top 10 existing features\n",
    "def Polynomials_top10(df, top10_cols):\n",
    "    for i in range(1,11):\n",
    "        new_cols_2 = top10_cols[0][i] + '_s' + str(2)\n",
    "        new_cols_3 = top10_cols[0][i] + '_s' + str(3)\n",
    "        new_cols_sq = top10_cols[0][i] + '_sq'\n",
    "        \n",
    "        df[new_cols_2] = df[top10_cols[0][i]] ** 2\n",
    "        df[new_cols_3] = df[top10_cols[0][i]] ** 3\n",
    "        df[new_cols_sq] = np.sqrt(df[top10_cols[0][i]]) \n",
    "        \n",
    "    return df\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MSSubClass</th>\n",
       "      <th>MSZoning</th>\n",
       "      <th>LotFrontage</th>\n",
       "      <th>LotArea</th>\n",
       "      <th>Street</th>\n",
       "      <th>Alley</th>\n",
       "      <th>LotShape</th>\n",
       "      <th>LandContour</th>\n",
       "      <th>Utilities</th>\n",
       "      <th>LotConfig</th>\n",
       "      <th>...</th>\n",
       "      <th>TotalBsmtSF_sq</th>\n",
       "      <th>TotalBath_s2</th>\n",
       "      <th>TotalBath_s3</th>\n",
       "      <th>TotalBath_sq</th>\n",
       "      <th>ExterQual_s2</th>\n",
       "      <th>ExterQual_s3</th>\n",
       "      <th>ExterQual_sq</th>\n",
       "      <th>GarageScore_s2</th>\n",
       "      <th>GarageScore_s3</th>\n",
       "      <th>GarageScore_sq</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>SC60</td>\n",
       "      <td>RL</td>\n",
       "      <td>65.000</td>\n",
       "      <td>8450</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>4</td>\n",
       "      <td>Inside</td>\n",
       "      <td>...</td>\n",
       "      <td>29.257</td>\n",
       "      <td>12.250</td>\n",
       "      <td>42.875</td>\n",
       "      <td>1.871</td>\n",
       "      <td>4</td>\n",
       "      <td>8</td>\n",
       "      <td>1.414</td>\n",
       "      <td>300304</td>\n",
       "      <td>164566592</td>\n",
       "      <td>23.409</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>SC20</td>\n",
       "      <td>RL</td>\n",
       "      <td>80.000</td>\n",
       "      <td>9600</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>4</td>\n",
       "      <td>FR2</td>\n",
       "      <td>...</td>\n",
       "      <td>35.525</td>\n",
       "      <td>6.250</td>\n",
       "      <td>15.625</td>\n",
       "      <td>1.581</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000</td>\n",
       "      <td>211600</td>\n",
       "      <td>97336000</td>\n",
       "      <td>21.448</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>SC60</td>\n",
       "      <td>RL</td>\n",
       "      <td>68.000</td>\n",
       "      <td>11250</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>4</td>\n",
       "      <td>Inside</td>\n",
       "      <td>...</td>\n",
       "      <td>30.332</td>\n",
       "      <td>12.250</td>\n",
       "      <td>42.875</td>\n",
       "      <td>1.871</td>\n",
       "      <td>4</td>\n",
       "      <td>8</td>\n",
       "      <td>1.414</td>\n",
       "      <td>369664</td>\n",
       "      <td>224755712</td>\n",
       "      <td>24.658</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>SC70</td>\n",
       "      <td>RL</td>\n",
       "      <td>60.000</td>\n",
       "      <td>9550</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>4</td>\n",
       "      <td>Corner</td>\n",
       "      <td>...</td>\n",
       "      <td>27.495</td>\n",
       "      <td>4.000</td>\n",
       "      <td>8.000</td>\n",
       "      <td>1.414</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000</td>\n",
       "      <td>412164</td>\n",
       "      <td>264609288</td>\n",
       "      <td>25.338</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>SC60</td>\n",
       "      <td>RL</td>\n",
       "      <td>84.000</td>\n",
       "      <td>14260</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>4</td>\n",
       "      <td>FR2</td>\n",
       "      <td>...</td>\n",
       "      <td>33.838</td>\n",
       "      <td>12.250</td>\n",
       "      <td>42.875</td>\n",
       "      <td>1.871</td>\n",
       "      <td>4</td>\n",
       "      <td>8</td>\n",
       "      <td>1.414</td>\n",
       "      <td>698896</td>\n",
       "      <td>584277056</td>\n",
       "      <td>28.914</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 144 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "  MSSubClass MSZoning  LotFrontage  LotArea  Street  Alley  LotShape  \\\n",
       "0       SC60       RL       65.000     8450       2      0         4   \n",
       "1       SC20       RL       80.000     9600       2      0         4   \n",
       "2       SC60       RL       68.000    11250       2      0         3   \n",
       "3       SC70       RL       60.000     9550       2      0         3   \n",
       "4       SC60       RL       84.000    14260       2      0         3   \n",
       "\n",
       "  LandContour  Utilities LotConfig       ...        TotalBsmtSF_sq  \\\n",
       "0         Lvl          4    Inside       ...                29.257   \n",
       "1         Lvl          4       FR2       ...                35.525   \n",
       "2         Lvl          4    Inside       ...                30.332   \n",
       "3         Lvl          4    Corner       ...                27.495   \n",
       "4         Lvl          4       FR2       ...                33.838   \n",
       "\n",
       "  TotalBath_s2 TotalBath_s3 TotalBath_sq ExterQual_s2 ExterQual_s3  \\\n",
       "0       12.250       42.875        1.871            4            8   \n",
       "1        6.250       15.625        1.581            1            1   \n",
       "2       12.250       42.875        1.871            4            8   \n",
       "3        4.000        8.000        1.414            1            1   \n",
       "4       12.250       42.875        1.871            4            8   \n",
       "\n",
       "   ExterQual_sq  GarageScore_s2  GarageScore_s3  GarageScore_sq  \n",
       "0         1.414          300304       164566592          23.409  \n",
       "1         1.000          211600        97336000          21.448  \n",
       "2         1.414          369664       224755712          24.658  \n",
       "3         1.000          412164       264609288          25.338  \n",
       "4         1.414          698896       584277056          28.914  \n",
       "\n",
       "[5 rows x 144 columns]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data = Polynomials_top10(train_data, top10_cols)\n",
    "test_data = Polynomials_top10(test_data,top10_cols)\n",
    "train_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#对训练集的其他数值型特征进行空缺值填补（中值填补）\n",
    "#返回填补后的dataframe，以及每列的中值，用于填补测试集的空缺值\n",
    "# 数值型特征还要进行数据标准化\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "def fillna_numerical_train(df):\n",
    "    numerical_features = df.select_dtypes(exclude = [\"object\"]).columns\n",
    "    \n",
    "    numerical_features = numerical_features.drop(\"SalePrice\")\n",
    "    print(\"Numerical features : \" + str(len(numerical_features)))\n",
    "\n",
    "    df.info()\n",
    "    df_num = df[numerical_features]\n",
    "    #df_num.info()\n",
    "    \n",
    "    medians = df_num.median() \n",
    "    # Handle remaining missing values for numerical features by using median as replacement\n",
    "    print(\"NAs for numerical features in df : \" + str(df_num.isnull().values.sum()))\n",
    "    df_num = df_num.fillna(medians)\n",
    "    print(\"Remaining NAs for numerical features in df : \" + str(df_num.isnull().values.sum()))\n",
    "\n",
    "    #df_num.info()\n",
    "    # 分别初始化对特征和目标值的标准化器\n",
    "    ss_X = StandardScaler()\n",
    "\n",
    "    # 对训练特征进行标准化处理\n",
    "    temp = ss_X.fit_transform(df_num)\n",
    "    df_num = pd.DataFrame(data=temp, columns=numerical_features, index =df_num.index)\n",
    "    \n",
    "    return df_num, medians, ss_X\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Numerical features : 97\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 1452 entries, 0 to 1459\n",
      "Columns: 144 entries, MSSubClass to GarageScore_sq\n",
      "dtypes: float64(16), int64(82), object(46)\n",
      "memory usage: 1.6+ MB\n",
      "NAs for numerical features in df : 81\n",
      "Remaining NAs for numerical features in df : 0\n"
     ]
    }
   ],
   "source": [
    "train_num, medians, ss_X = fillna_numerical_train(train_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 1452 entries, 0 to 1459\n",
      "Data columns (total 97 columns):\n",
      "LotFrontage       1452 non-null float64\n",
      "LotArea           1452 non-null float64\n",
      "Street            1452 non-null float64\n",
      "Alley             1452 non-null float64\n",
      "LotShape          1452 non-null float64\n",
      "Utilities         1452 non-null float64\n",
      "LandSlope         1452 non-null float64\n",
      "OverallQual       1452 non-null float64\n",
      "OverallCond       1452 non-null float64\n",
      "YearBuilt         1452 non-null float64\n",
      "YearRemodAdd      1452 non-null float64\n",
      "MasVnrArea        1452 non-null float64\n",
      "ExterQual         1452 non-null float64\n",
      "ExterCond         1452 non-null float64\n",
      "BsmtQual          1452 non-null float64\n",
      "BsmtCond          1452 non-null float64\n",
      "BsmtExposure      1452 non-null float64\n",
      "BsmtFinType1      1452 non-null float64\n",
      "BsmtFinSF1        1452 non-null float64\n",
      "BsmtFinType2      1452 non-null float64\n",
      "BsmtFinSF2        1452 non-null float64\n",
      "BsmtUnfSF         1452 non-null float64\n",
      "TotalBsmtSF       1452 non-null float64\n",
      "HeatingQC         1452 non-null float64\n",
      "1stFlrSF          1452 non-null float64\n",
      "2ndFlrSF          1452 non-null float64\n",
      "LowQualFinSF      1452 non-null float64\n",
      "GrLivArea         1452 non-null float64\n",
      "BsmtFullBath      1452 non-null float64\n",
      "BsmtHalfBath      1452 non-null float64\n",
      "FullBath          1452 non-null float64\n",
      "HalfBath          1452 non-null float64\n",
      "BedroomAbvGr      1452 non-null float64\n",
      "KitchenAbvGr      1452 non-null float64\n",
      "KitchenQual       1452 non-null float64\n",
      "TotRmsAbvGrd      1452 non-null float64\n",
      "Functional        1452 non-null float64\n",
      "Fireplaces        1452 non-null float64\n",
      "FireplaceQu       1452 non-null float64\n",
      "GarageYrBlt       1452 non-null float64\n",
      "GarageCars        1452 non-null float64\n",
      "GarageArea        1452 non-null float64\n",
      "GarageQual        1452 non-null float64\n",
      "GarageCond        1452 non-null float64\n",
      "PavedDrive        1452 non-null float64\n",
      "WoodDeckSF        1452 non-null float64\n",
      "OpenPorchSF       1452 non-null float64\n",
      "EnclosedPorch     1452 non-null float64\n",
      "3SsnPorch         1452 non-null float64\n",
      "ScreenPorch       1452 non-null float64\n",
      "PoolArea          1452 non-null float64\n",
      "PoolQC            1452 non-null float64\n",
      "MiscVal           1452 non-null float64\n",
      "YrSold            1452 non-null float64\n",
      "OverallGrade      1452 non-null float64\n",
      "GarageGrade       1452 non-null float64\n",
      "ExterGrade        1452 non-null float64\n",
      "KitchenScore      1452 non-null float64\n",
      "FireplaceScore    1452 non-null float64\n",
      "GarageScore       1452 non-null float64\n",
      "PoolScore         1452 non-null float64\n",
      "TotalBath         1452 non-null float64\n",
      "AllSF             1452 non-null float64\n",
      "AllFlrsSF         1452 non-null float64\n",
      "AllPorchSF        1452 non-null float64\n",
      "HasMasVnr         1452 non-null float64\n",
      "BoughtOffPlan     1452 non-null float64\n",
      "AllSF_s2          1452 non-null float64\n",
      "AllSF_s3          1452 non-null float64\n",
      "AllSF_sq          1452 non-null float64\n",
      "AllFlrsSF_s2      1452 non-null float64\n",
      "AllFlrsSF_s3      1452 non-null float64\n",
      "AllFlrsSF_sq      1452 non-null float64\n",
      "GrLivArea_s2      1452 non-null float64\n",
      "GrLivArea_s3      1452 non-null float64\n",
      "GrLivArea_sq      1452 non-null float64\n",
      "OverallQual_s2    1452 non-null float64\n",
      "OverallQual_s3    1452 non-null float64\n",
      "OverallQual_sq    1452 non-null float64\n",
      "GarageCars_s2     1452 non-null float64\n",
      "GarageCars_s3     1452 non-null float64\n",
      "GarageCars_sq     1452 non-null float64\n",
      "GarageArea_s2     1452 non-null float64\n",
      "GarageArea_s3     1452 non-null float64\n",
      "GarageArea_sq     1452 non-null float64\n",
      "TotalBsmtSF_s2    1452 non-null float64\n",
      "TotalBsmtSF_s3    1452 non-null float64\n",
      "TotalBsmtSF_sq    1452 non-null float64\n",
      "TotalBath_s2      1452 non-null float64\n",
      "TotalBath_s3      1452 non-null float64\n",
      "TotalBath_sq      1452 non-null float64\n",
      "ExterQual_s2      1452 non-null float64\n",
      "ExterQual_s3      1452 non-null float64\n",
      "ExterQual_sq      1452 non-null float64\n",
      "GarageScore_s2    1452 non-null float64\n",
      "GarageScore_s3    1452 non-null float64\n",
      "GarageScore_sq    1452 non-null float64\n",
      "dtypes: float64(97)\n",
      "memory usage: 1.1 MB\n"
     ]
    }
   ],
   "source": [
    "train_num.info()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#对测试集的其他数值型特征进行空缺值填补（用训练集中相应列的中值填补）\n",
    "def fillna_numerical_test(df, medians, ss_X):\n",
    "    numerical_features = df.select_dtypes(exclude = [\"object\"]).columns\n",
    "    #numerical_features = numerical_features.drop(\"SalePrice\")  #测试集中没有SalePrice\n",
    "    print(\"Numerical features : \" + str(len(numerical_features)))\n",
    "\n",
    "    df_num = df[numerical_features]\n",
    "    \n",
    "    # Handle remaining missing values for numerical features by using median as replacement\n",
    "    print(\"NAs for numerical features in df : \" + str(df_num.isnull().values.sum()))\n",
    "    df_num = df_num.fillna(medians)\n",
    "    print(\"Remaining NAs for numerical features in df : \" + str(df_num.isnull().values.sum()))\n",
    "\n",
    "    #对数值特征进行标准化\n",
    "    temp = ss_X.transform(df_num)\n",
    "    df_num = pd.DataFrame(data=temp, columns=numerical_features, index =df_num.index )\n",
    "    return df_num\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Numerical features : 97\n",
      "NAs for numerical features in df : 88\n",
      "Remaining NAs for numerical features in df : 0\n"
     ]
    }
   ],
   "source": [
    "test_num = fillna_numerical_test(test_data, medians, ss_X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1459 entries, 0 to 1458\n",
      "Data columns (total 97 columns):\n",
      "LotFrontage       1459 non-null float64\n",
      "LotArea           1459 non-null float64\n",
      "Street            1459 non-null float64\n",
      "Alley             1459 non-null float64\n",
      "LotShape          1459 non-null float64\n",
      "Utilities         1459 non-null float64\n",
      "LandSlope         1459 non-null float64\n",
      "OverallQual       1459 non-null float64\n",
      "OverallCond       1459 non-null float64\n",
      "YearBuilt         1459 non-null float64\n",
      "YearRemodAdd      1459 non-null float64\n",
      "MasVnrArea        1459 non-null float64\n",
      "ExterQual         1459 non-null float64\n",
      "ExterCond         1459 non-null float64\n",
      "BsmtQual          1459 non-null float64\n",
      "BsmtCond          1459 non-null float64\n",
      "BsmtExposure      1459 non-null float64\n",
      "BsmtFinType1      1459 non-null float64\n",
      "BsmtFinSF1        1459 non-null float64\n",
      "BsmtFinType2      1459 non-null float64\n",
      "BsmtFinSF2        1459 non-null float64\n",
      "BsmtUnfSF         1459 non-null float64\n",
      "TotalBsmtSF       1459 non-null float64\n",
      "HeatingQC         1459 non-null float64\n",
      "1stFlrSF          1459 non-null float64\n",
      "2ndFlrSF          1459 non-null float64\n",
      "LowQualFinSF      1459 non-null float64\n",
      "GrLivArea         1459 non-null float64\n",
      "BsmtFullBath      1459 non-null float64\n",
      "BsmtHalfBath      1459 non-null float64\n",
      "FullBath          1459 non-null float64\n",
      "HalfBath          1459 non-null float64\n",
      "BedroomAbvGr      1459 non-null float64\n",
      "KitchenAbvGr      1459 non-null float64\n",
      "KitchenQual       1459 non-null float64\n",
      "TotRmsAbvGrd      1459 non-null float64\n",
      "Functional        1459 non-null float64\n",
      "Fireplaces        1459 non-null float64\n",
      "FireplaceQu       1459 non-null float64\n",
      "GarageYrBlt       1459 non-null float64\n",
      "GarageCars        1459 non-null float64\n",
      "GarageArea        1459 non-null float64\n",
      "GarageQual        1459 non-null float64\n",
      "GarageCond        1459 non-null float64\n",
      "PavedDrive        1459 non-null float64\n",
      "WoodDeckSF        1459 non-null float64\n",
      "OpenPorchSF       1459 non-null float64\n",
      "EnclosedPorch     1459 non-null float64\n",
      "3SsnPorch         1459 non-null float64\n",
      "ScreenPorch       1459 non-null float64\n",
      "PoolArea          1459 non-null float64\n",
      "PoolQC            1459 non-null float64\n",
      "MiscVal           1459 non-null float64\n",
      "YrSold            1459 non-null float64\n",
      "OverallGrade      1459 non-null float64\n",
      "GarageGrade       1459 non-null float64\n",
      "ExterGrade        1459 non-null float64\n",
      "KitchenScore      1459 non-null float64\n",
      "FireplaceScore    1459 non-null float64\n",
      "GarageScore       1459 non-null float64\n",
      "PoolScore         1459 non-null float64\n",
      "TotalBath         1459 non-null float64\n",
      "AllSF             1459 non-null float64\n",
      "AllFlrsSF         1459 non-null float64\n",
      "AllPorchSF        1459 non-null float64\n",
      "HasMasVnr         1459 non-null float64\n",
      "BoughtOffPlan     1459 non-null float64\n",
      "AllSF_s2          1459 non-null float64\n",
      "AllSF_s3          1459 non-null float64\n",
      "AllSF_sq          1459 non-null float64\n",
      "AllFlrsSF_s2      1459 non-null float64\n",
      "AllFlrsSF_s3      1459 non-null float64\n",
      "AllFlrsSF_sq      1459 non-null float64\n",
      "GrLivArea_s2      1459 non-null float64\n",
      "GrLivArea_s3      1459 non-null float64\n",
      "GrLivArea_sq      1459 non-null float64\n",
      "OverallQual_s2    1459 non-null float64\n",
      "OverallQual_s3    1459 non-null float64\n",
      "OverallQual_sq    1459 non-null float64\n",
      "GarageCars_s2     1459 non-null float64\n",
      "GarageCars_s3     1459 non-null float64\n",
      "GarageCars_sq     1459 non-null float64\n",
      "GarageArea_s2     1459 non-null float64\n",
      "GarageArea_s3     1459 non-null float64\n",
      "GarageArea_sq     1459 non-null float64\n",
      "TotalBsmtSF_s2    1459 non-null float64\n",
      "TotalBsmtSF_s3    1459 non-null float64\n",
      "TotalBsmtSF_sq    1459 non-null float64\n",
      "TotalBath_s2      1459 non-null float64\n",
      "TotalBath_s3      1459 non-null float64\n",
      "TotalBath_sq      1459 non-null float64\n",
      "ExterQual_s2      1459 non-null float64\n",
      "ExterQual_s3      1459 non-null float64\n",
      "ExterQual_sq      1459 non-null float64\n",
      "GarageScore_s2    1459 non-null float64\n",
      "GarageScore_s3    1459 non-null float64\n",
      "GarageScore_sq    1459 non-null float64\n",
      "dtypes: float64(97)\n",
      "memory usage: 1.1 MB\n"
     ]
    }
   ],
   "source": [
    "test_num.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def get_dummies_cat(df):\n",
    "    categorical_features = df.select_dtypes(include = [\"object\"]).columns\n",
    "    print(\"Categorical features : \" + str(len(categorical_features)))\n",
    "    df_cat = df[categorical_features]\n",
    "    \n",
    "\n",
    "    # Create dummy features for categorical values via one-hot encoding\n",
    "    print(\"NAs for categorical features in df : \" + str(df_cat.isnull().values.sum()))\n",
    "    df_cat = pd.get_dummies(df_cat,dummy_na=True)\n",
    "    print(\"Remaining NAs for categorical features in df : \" + str(df_cat.isnull().values.sum()))\n",
    "    \n",
    "    return df_cat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Categorical features : 46\n",
      "NAs for categorical features in df : 61139\n",
      "Remaining NAs for categorical features in df : 0\n"
     ]
    }
   ],
   "source": [
    "#必须考虑类别型特征的取值范围（训练集和测试的取值范围可能不同）\n",
    "#train_cat = get_dummies_cat(train)\n",
    "#test_cat = get_dummies_cat(test)\n",
    "\n",
    "n_train_samples = train_data.shape[0]  \n",
    "train_test = pd.concat((train_data, test_data), axis=0)\n",
    "train_test_cat = get_dummies_cat(train_test)\n",
    "   \n",
    "train_cat = train_test_cat.iloc[:n_train_samples, :]\n",
    "test_cat = train_test_cat.iloc[n_train_samples:, :]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 1452 entries, 0 to 1459\n",
      "Columns: 246 entries, BldgType_1Fam to SimplPoolScore_nan\n",
      "dtypes: uint8(246)\n",
      "memory usage: 360.2 KB\n"
     ]
    }
   ],
   "source": [
    "train_cat.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Join categorical and numerical features\n",
    "def joint_num_cat(df_num, df_cat):\n",
    "    df = pd.concat([df_num, df_cat], axis = 1, ignore_index=True)\n",
    "    print(\"New number of features : \" + str(df.shape[1]))\n",
    "    \n",
    "    return df\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "New number of features : 343\n",
      "New number of features : 343\n"
     ]
    }
   ],
   "source": [
    "FE_train = joint_num_cat(train_num, train_cat)\n",
    "FE_test = joint_num_cat(test_num, test_cat)\n",
    "\n",
    "FE_train = pd.concat([FE_train, train_data['SalePrice']], axis = 1)\n",
    "FE_test = pd.concat([test_id,FE_test], axis = 1)\n",
    "\n",
    "FE_train.to_csv('AmesHouse_FE_train.csv', index=False)\n",
    "FE_test.to_csv('AmesHouse_FE_test.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 1452 entries, 0 to 1459\n",
      "Columns: 344 entries, 0 to SalePrice\n",
      "dtypes: float64(97), int64(1), uint8(246)\n",
      "memory usage: 1.4 MB\n"
     ]
    }
   ],
   "source": [
    "FE_train.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1459 entries, 0 to 1458\n",
      "Columns: 344 entries, Id to 342\n",
      "dtypes: float64(97), int64(1), uint8(246)\n",
      "memory usage: 1.4 MB\n"
     ]
    }
   ],
   "source": [
    "FE_test.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 确定模型类型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "尝试缺省参数的线性回归"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "y = FE_train['SalePrice'].values\n",
    "y = np.log(y)\n",
    "X = FE_train.drop(['SalePrice'], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Anaconda2\\lib\\site-packages\\sklearn\\cross_validation.py:41: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.\n",
      "  \"This module will be removed in 0.20.\", DeprecationWarning)\n"
     ]
    }
   ],
   "source": [
    "#将数据分割训练数据与测试数据\n",
    "from sklearn.cross_validation import train_test_split\n",
    "\n",
    "# 随机采样20%的数据构建测试样本，其余作为训练样本\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=33, test_size=0.2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 线性回归\n",
    "#class sklearn.linear_model.LinearRegression(fit_intercept=True, normalize=False, copy_X=True, n_jobs=1)\n",
    "from sklearn.linear_model import LinearRegression\n",
    "\n",
    "# 使用默认配置初始化\n",
    "lr = LinearRegression()\n",
    "\n",
    "# 训练模型参数\n",
    "model = lr.fit(X_train, y_train)\n",
    "\n",
    "# 预测，下面计算score会自动调用predict\n",
    "lr_y_predict = model.predict(X_test)\n",
    "lr_y_predict_train = model.predict(X_train)\n",
    "\n",
    "#lr.coef_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The value of default measurement of LinearRegression on test is 0.892507201837\n",
      "The value of default measurement of LinearRegression on train is 0.948556252591\n"
     ]
    }
   ],
   "source": [
    "# 使用LinearRegression模型自带的评估模块（r2_score），并输出评估结果\n",
    "\n",
    "#测试集\n",
    "print 'The value of default measurement of LinearRegression on test is', model.score(X_test, y_test)\n",
    "\n",
    "#训练集\n",
    "print 'The value of default measurement of LinearRegression on train is', model.score(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "RMSE on test is:  0.132776673167\n",
      "RMSE on train is:  0.0890839255324\n"
     ]
    }
   ],
   "source": [
    "#RMSE这个值比r平方值更直观，它表示我们的预测值和实际值之间的距离\n",
    "from sklearn.metrics import mean_squared_error\n",
    "\n",
    "print 'RMSE on test is: ', np.sqrt(mean_squared_error(y_test, lr_y_predict))\n",
    "print 'RMSE on train is: ',np.sqrt( mean_squared_error(y_train, lr_y_predict_train))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAe8AAAFsCAYAAADlrTG7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAHuBJREFUeJzt3XucXWV97/HPjyQmlkAQmEAgYAKC\nynWCA5JjgdiIYEGC51guh2tBQkF6rB6torVMUU+1oB49UNqoCAhCAItwvJwDJwVTOYImmEauEjAp\nCWkIQS7hIiT8+sdeE3eSmczO7D2XJ/N5v17zmr2ftfZav/1MMt/9PGvNWpGZSJKkcmw12AVIkqTN\nY3hLklQYw1uSpMIY3pIkFcbwliSpMIa3JEmFMbylHkTEAxExbbDrGEwR8YGIeCIiVkfElAHc7+qI\n2KOHZWdGxE9btJ/FEfGeVmxLGkiGt4al7n5pbxgKmblvZt7Vy3YmRURGxMh+KnWwXQpckJljM/OX\nGy6s3vuLVdgui4ivRMSIZnda7e/xZrcjbakMb2kIGwIfCt4MPNDLOgdm5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/nll/dpO9/85jc3Cu6hoKOjo9+De+3atS3b\nluEtSdosU6dOZdmyZeueX3LJJRx88MEccMABXHTRRQC8+OKLHHPMMRx44IHst99+zJ49G6iNersu\nh/3tb3+bvffemyOOOIK777573fbOPPNMbr755nXPx44dC8Dq1auZPn06Bx10EPvvvz+33nrrRrUt\nX76cww8/nPb2dvbbbz/+5V/+paH3dNddd3HssccC0NnZyVlnncW0adPYY4891gv1a6+9lkMOOYT2\n9nbOPffcdYF83nnn0dHRwb777ruuD6B2+e+LL76YP/zDP+Smm25qqJZGOG0uSWrY2rVrmTNnDmef\nfTYAt99+O48++ig///nPyUyOO+445s6dy8qVK9lll1344Q9/CMBzzz233naWL1/ORRddxPz58xk3\nbhzvfve7mTJlyib3PWbMGG655Ra23XZbnn76aQ499FCOO+649U7++u53v8tRRx3FZz7zGdauXctL\nL73Up/f58MMPc+edd/LCCy/w1re+lfPOO49FixYxe/Zs7r77bkaNGsX555/Pddddx+mnn84XvvAF\ntt9+e9auXcv06dNZuHAhBxxwwLq6f/rTn/apjp4Y3pKkXr388su0t7ezePFi3vGOd3DkkUcCtfC+\n/fbb1wXv6tWrefTRRznssMP4+Mc/zic/+UmOPfZYDjvssPW2d++99zJt2jTa2mo30DrxxBP59a9/\nvckaMpNPf/rTzJ07l6222oply5axYsUKdt5553XrHHzwwZx11lm89tprHH/88bS3t/fp/R5zzDGM\nHj2a0aNHM378eFasWMGcOXOYP38+Bx988Lo+GT9+PAA33ngjs2bNYs2aNSxfvpwHH3xwXXifeOKJ\nfaphU5w2lyT1quuY95IlS3j11VfXHfPOTC688EIWLFjAggULWLRoEWeffTZ777038+fPZ//99+fC\nCy/k4osv3mibPf251MiRI3n99dfXbf/VV18F4LrrrmPlypXMnz+fBQsWsNNOO230t9KHH344c+fO\nZdddd+W0007jmmuu6dP7HT169LrHI0aMYM2aNWQmZ5xxxrr3+sgjj9DZ2clvfvMbLr30UubMmcPC\nhQs55phj1qtr66237lMNm+LIW9IWZ3POxm71mdtbunHjxvH1r3+dGTNmcN5553HUUUfx2c9+llNO\nOYWxY8eybNkyRo0axZo1a9h+++059dRTGTt2LFddddV623nnO9/JRz7yEVatWsW2227LTTfdxIEH\nHgjUjhPPnz+fE044gVtvvZXXXnsNqE29jx8/nlGjRnHnnXeyZMnGd89csmQJu+66K+eccw4vvvgi\n9913H6effnpL3vv06dOZMWMGH/3oRxk/fjzPPPMML7zwAs8//zxbb70148aNY8WKFfz4xz9m2rRp\nLdlnTwxvSSrMYH/gmDJlCgceeCA33HADp512Gg899BBTp04FaieXXXvttSxatIhPfOITbLXVVowa\nNYorrrhivW1MmDCBzs5Opk6dyoQJEzjooIPWnfx1zjnnMGPGDA455BCmT5++buR6yimn8P73v5+O\njg7a29t529vetlFtd911F5dccgmjRo1i7NixPY68jznmmHXXFZ86dSof/vCHe33f++yzD5///Od5\n73vfy+uvv86oUaO4/PLLOfTQQ5kyZQr77rsve+yxB+9617sa78w+iszs9530pqOjI7vOPpSkZm1p\nI++HHnqIt7/97YNdhlqsu59rRMzPzI4eXrKOx7wlSSqM4S1JUmEMb0kqwFA4xKnWafbnaXhL0hA3\nZswYVq1aZYBvIbru5z1mzJg+b8OzzSVpiJs4cSJLly5l5cqVg12KWmTMmDFMnDixz683vCVpiBs1\nahSTJ08e7DI0hDhtLklSYQxvSZIKY3hLklQYw1uSpMIY3pIkFabX8I6IKyPiqYi4v65tdkQsqL4W\nR8SCqn1SRLxct+wf+rN4SZKGo0b+VOwq4DJg3a1ZMnPdncUj4svAc3XrP5aZfbv7uSRJ6lWv4Z2Z\ncyNiUnfLonYn9ROAP2ptWZIkqSfNHvM+DFiRmY/WtU2OiF9GxE8i4rCeXhgRMyNiXkTM86pBkiQ1\nrtnwPhm4vu75cmD3zJwCfAz4bkRs290LM3NWZnZkZkdbW1uTZUiSNHz0ObwjYiTwn4HZXW2Z+bvM\nXFU9ng88BuzdbJGSJOn3mhl5vwd4ODOXdjVERFtEjKge7wHsBTzeXImSJKleI38qdj3wM+CtEbE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OBOA7wBmZ+XoraitYr5djbnCd4arhvomIU4EO4Ih+ragsm+y/asDyVWo5\n0TLDLrwz8z09LYuIFRExITOXV78cuzuWvRT4ZWY+Xr3m+8ChDJPwbkH/TQUOi4jzgbHAGyJidWZu\n6vj4FqMF/UdEbAv8EPirzLynn0otSSOXY+5aZ2lEjATGAc8MTHlDXkOXs46I91D7kHlEZv5ugGor\nQW/9tw2wH3BXNWDZGbgtIo7LzHl93anT5uu7DTijenwGcGs36/wCeFNEdB1n/CPA+5TX9Np/mXlK\nZu6emZOAjwPXDJfgbkCv/VddbvgWav120wDWNpQ1cjnm+r79IPDP6RWquvTaf9W07z8Cx2WmJ+iu\nb5P9l5nPZeaOmTmp+r13D7V+7HNwg+G9oS8CR0bEo8CR1XMioiMivgmQmWuphc6ciPgVtSmTbwxS\nvUNNr/2nTWqk/04ADgfOjIgF1Vf74JQ7NFTHsLsux/wQcGNmPhARF0fEcdVq3wJ2iIhFwMfY9F9C\nDCsN9t8l1GbKbqr+zXmvikqD/ddyXh5VkqTCOPKWJKkwhrckSYUxvCVJKozhLUlSYQxvSZIKY3hL\nklQYw1uSpML8Bw6X7/Zl5xD9AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xf90ea20>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#在训练集上观察预测残差的分布，看是否符合模型假设：噪声为0均值的高斯噪声\n",
    "f, ax = plt.subplots(figsize=(7, 5)) \n",
    "f.tight_layout() \n",
    "ax.hist(y_train - lr_y_predict_train,bins=40, label='Residuals Linear', color='b', alpha=.5); \n",
    "ax.set_title(\"Histogram of Residuals\") \n",
    "ax.legend(loc='best');"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQ0AAADQCAYAAAAdxTRNAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB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WZvWZmfZr4vnFm\n9pyZVQX3FvnlAdo5xszWm1lZ8PtLzOwNM1tpZo+GbU/io+GJNFYBXOLuPzGzdP827gPucPclZtYJ\n+CvQvYnjegX79wJLzeyvQE3jdgCCM0kxs1OAm4C+7r7VzMozbE9ioNCQxt5396UhjjsH6NbwHzvQ\nzsxau/vu/Y6rcvfPAMxsNnAG8GKadgYCz7j7VoCG1wzakxgoNKSxnY3e1/PFy/wPbfTeCDdpuv+E\nWcP2zv0PbPS9TU2yhW1PYqA5DWlSMDn5mZl1NbMSYFijX78MXNmwYWanHuBrzjWzMjM7jNQdrhY3\n0+zLwIiGYUmj4UnY9iQGCg1J5yZSw4lXSN0npMGVQL9gwvIt4LIDfH4R8GdgOfCUu69I15i7vwHc\nASw0sxXAnRm2JzHQkqtEwszGAd3d/dqka5HsUk9DRDKinoaIZEQ9DRHJiEJDRDKi0BCRjCg0RCQj\nCg0Rycj/AzkKDmYr3zVdAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xfb15be0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#还可以观察预测值与真值的散点图\n",
    "plt.figure(figsize=(4, 3))\n",
    "plt.scatter(y_train, lr_y_predict_train)\n",
    "plt.plot([-3, 3], [-3, 3], '--k')   #数据已经标准化，3倍标准差即可\n",
    "plt.axis('tight')\n",
    "plt.xlabel('True price')\n",
    "plt.ylabel('Predicted price')\n",
    "plt.tight_layout()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  2.65210831e-04,   2.46892573e-02,   1.26509895e-02,\n",
       "         2.40926437e-03,   1.83811069e-03,   1.14702449e-02,\n",
       "         4.39898434e-03,   1.72996416e-02,   7.78109388e-03,\n",
       "         6.30620394e-02,   1.72928003e-02,   8.34127730e-03,\n",
       "        -5.08363839e-04,  -1.54385864e-02,   1.21250566e-03,\n",
       "         1.05714569e-03,   1.65406263e-02,   5.22583380e-03,\n",
       "         2.26131149e-02,  -7.80511258e-04,   7.44555763e-04,\n",
       "        -1.20311447e-02,   1.09913362e-02,   1.48029952e-02,\n",
       "        -4.29239972e-03,  -1.03355730e-02,   2.73434260e-03,\n",
       "        -1.18934806e-02,  -1.49286620e-02,  -1.70015254e-03,\n",
       "        -7.14215047e-03,   3.52203357e-03,  -1.24420425e-02,\n",
       "        -1.55059782e-02,   5.97796212e-03,   6.30142965e-03,\n",
       "         2.41370080e-02,   4.12078035e-03,   5.64373629e-03,\n",
       "        -4.10727494e-04,   1.68067101e-02,   2.95328969e-03,\n",
       "        -2.26049208e-04,  -1.65340152e-02,   3.84521625e-03,\n",
       "         1.24529172e-02,   6.72461592e-03,  -9.14292473e-04,\n",
       "         9.21066492e-04,   9.17345662e-03,   1.33205981e-02,\n",
       "        -7.51364307e-02,   1.32540898e-02,   6.31619540e-04,\n",
       "         4.22440684e-02,   5.05185994e-03,   1.36151454e-02,\n",
       "        -2.30583452e-03,   4.12078035e-03,  -1.79128140e-03,\n",
       "         6.30770391e-02,  -1.40761336e-02,  -1.83347400e-03,\n",
       "        -1.22781288e-02,   8.80117456e-03,   6.41538097e-02,\n",
       "         4.67275644e-04,  -2.88713633e-02,   3.71257273e-02,\n",
       "         1.10504645e-01,  -3.75357595e-02,   2.81611526e-03,\n",
       "         6.73324340e-02,  -3.09082057e-02,   4.03559596e-02,\n",
       "         6.96928250e-02,  -2.17767918e-02,  -4.53059900e-02,\n",
       "         4.51526327e-02,   2.87522299e-03,   1.32244845e-02,\n",
       "        -1.88104608e-03,  -6.35625144e-04,   7.00817641e-03,\n",
       "        -4.77687625e-03,   4.25302104e-03,  -9.53016696e-03,\n",
       "        -2.14237657e-02,  -3.88608739e-02,   4.86174573e-02,\n",
       "         4.28999260e-02,  -5.08363839e-04,  -5.08363839e-04,\n",
       "        -5.08363839e-04,  -1.06737842e-02,   2.60633344e-02,\n",
       "         3.48528581e-03,   1.30685936e-01,   8.06439739e-02,\n",
       "         8.59848604e-02,   5.93968441e-02,   8.02128857e-02,\n",
       "         0.00000000e+00,   1.98128290e-01,   2.38796210e-01,\n",
       "         0.00000000e+00,   2.97933438e-02,   4.06498079e-02,\n",
       "         7.35176736e-02,   1.20640999e-03,   8.66472038e-02,\n",
       "         1.34830003e-02,   5.94939437e-02,   2.76582005e-02,\n",
       "         1.04474917e-01,   0.00000000e+00,   5.57654079e-02,\n",
       "         9.52647823e-02,   1.29160795e-01,   4.18794096e-02,\n",
       "         0.00000000e+00,  -3.55433921e-03,   3.61149951e-02,\n",
       "         8.22934497e-02,   0.00000000e+00,   1.19301240e-01,\n",
       "         1.52369764e-01,   3.85658792e-02,   7.42203172e-03,\n",
       "         1.19265585e-01,   0.00000000e+00,   2.70779488e-02,\n",
       "        -1.11282112e-02,  -6.64575211e-02,   9.82194117e-02,\n",
       "        -5.01159346e-03,   1.01713341e-02,   6.15964414e-02,\n",
       "         7.99076063e-03,   4.37574527e-02,   4.81332446e-02,\n",
       "         1.84131453e-02,   1.13801960e-01,   2.55231196e-02,\n",
       "        -1.16065923e-03,   6.59976663e-02,   0.00000000e+00,\n",
       "         6.63366322e-03,  -1.38553586e-02,   1.92952867e-02,\n",
       "         1.87114493e-02,  -5.01159346e-03,   1.02375863e-01,\n",
       "         9.42772179e-03,   2.98950334e-02,   4.25719094e-02,\n",
       "        -1.37564271e-02,   8.65437804e-03,   3.56013470e-02,\n",
       "         4.20864224e-02,   5.30604258e-02,   7.29114541e-02,\n",
       "         2.83229252e-02,   0.00000000e+00,   1.07905809e-01,\n",
       "         5.78632920e-02,   1.12387283e-01,   6.34543512e-02,\n",
       "         9.53137648e-02,   0.00000000e+00,   1.08305414e-01,\n",
       "         1.05938100e-01,   1.23602305e-01,   7.56315300e-02,\n",
       "         3.53656733e-02,  -1.19185221e-02,   0.00000000e+00,\n",
       "         1.37327388e-01,   4.44968138e-02,   1.25255328e-01,\n",
       "         1.29844970e-01,   0.00000000e+00,   1.59450514e-02,\n",
       "         7.65797324e-02,   7.48544409e-02,   7.86077419e-02,\n",
       "         7.65874113e-02,   6.98533084e-02,   4.44968138e-02,\n",
       "         0.00000000e+00,   0.00000000e+00,   1.55141724e-01,\n",
       "         1.34034133e-01,   2.96534898e-02,   6.11581618e-02,\n",
       "         5.69369915e-02,   0.00000000e+00,   2.31160719e-02,\n",
       "         1.11320882e-01,   4.69540854e-02,  -5.08954835e-02,\n",
       "         9.06929377e-02,   6.07066504e-02,   5.98320347e-02,\n",
       "         9.51973221e-02,   0.00000000e+00,   1.26310734e-01,\n",
       "         1.14458937e-01,   8.61351136e-02,   1.10019716e-01,\n",
       "         0.00000000e+00,   1.07515107e-01,   1.28877441e-01,\n",
       "         5.84991228e-02,   5.08712649e-02,   9.11615648e-02,\n",
       "         0.00000000e+00,   5.77113415e-02,   0.00000000e+00,\n",
       "        -3.95230299e-02,   3.84670232e-02,   6.18386541e-02,\n",
       "         4.76198143e-02,  -7.57605935e-03,   6.69576105e-02,\n",
       "        -2.41935118e-02,   3.83707426e-02,   1.36752452e-02,\n",
       "         2.69466286e-02,   3.31297402e-02,   1.75877350e-03,\n",
       "         3.57566670e-02,   8.59848604e-02,   0.00000000e+00,\n",
       "        -9.71847941e-02,   1.25967755e-01,   1.78762946e-01,\n",
       "         1.30471956e-01,   9.89066372e-02,   0.00000000e+00,\n",
       "        -8.68287033e-03,   9.30417199e-02,   2.30354010e-01,\n",
       "         1.22211641e-01,   0.00000000e+00,  -3.55433921e-03,\n",
       "         2.27345406e-01,   1.18446628e-02,   2.06086345e-01,\n",
       "        -4.79757491e-03,   0.00000000e+00,   4.31875946e-02,\n",
       "         3.07818800e-02,   4.25955475e-02,   2.77291292e-02,\n",
       "         2.44842856e-02,   3.99277371e-02,   3.95857663e-02,\n",
       "         3.09769640e-02,   5.83936828e-02,   4.14603778e-02,\n",
       "         1.56216358e-02,   4.21798994e-02,   0.00000000e+00,\n",
       "        -4.14419952e-02,   3.61285256e-02,   1.17744479e-03,\n",
       "         6.99249958e-02,   2.53685116e-02,  -1.05865387e-03,\n",
       "         1.35210577e-01,  -3.58294807e-02,  -1.70130744e-02,\n",
       "        -1.51800914e-02,  -1.50341552e-01,  -3.28620157e-02,\n",
       "         1.07906615e-02,   6.88534711e-02,  -1.87797531e-02,\n",
       "         3.39476069e-02,   1.08401550e-01,  -1.91257162e-02,\n",
       "         1.87577138e-02,   1.71774021e-03,  -2.06723037e-03,\n",
       "         6.79644017e-02,   1.36422886e-01,   7.35844894e-03,\n",
       "         4.85995278e-02,   0.00000000e+00,   5.25838571e-02,\n",
       "         7.53925913e-02,   5.90962508e-02,   0.00000000e+00,\n",
       "         1.71818303e-02,   8.83608000e-02,   1.44309171e-01,\n",
       "         0.00000000e+00,   1.17416207e-01,   2.91663849e-02,\n",
       "         8.21120359e-02,   4.08923329e-02,   9.56754817e-02,\n",
       "         7.16620572e-02,   0.00000000e+00,   7.91870854e-02,\n",
       "         8.83264739e-02,   4.10685228e-02,   6.22343015e-02,\n",
       "         1.29568593e-01,   3.65395232e-02,   0.00000000e+00,\n",
       "        -1.32082236e-02,   1.21162687e-01,   5.01846090e-02,\n",
       "         1.12545976e-01,   2.89438114e-02,   4.84597813e-02,\n",
       "         1.14472999e-01,  -1.35888330e-02,  -1.20483075e-02,\n",
       "         0.00000000e+00,   4.36924500e-01,   4.36924500e-01,\n",
       "         4.36924500e-01,   4.36924500e-01,   4.36924500e-01,\n",
       "         4.36924500e-01,   4.36924500e-01,   4.36924500e-01,\n",
       "         4.36924500e-01,   4.36924500e-01,   4.36924500e-01,\n",
       "         4.36924500e-01,   4.36924500e-01,   4.36924500e-01,\n",
       "         4.36924500e-01,   4.36924500e-01,   4.36924500e-01,\n",
       "         4.36924500e-01,   4.36924500e-01,   4.36924500e-01,\n",
       "         4.36924500e-01])"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 线性模型，随机梯度下降优化模型参数\n",
    "# 随机梯度下降一般在大数据集上应用，其实本项目不适合用\n",
    "from sklearn.linear_model import SGDRegressor\n",
    "\n",
    "# 使用默认配置初始化线\n",
    "sgdr = SGDRegressor(max_iter=1000)\n",
    "\n",
    "# 训练：参数估计\n",
    "sgdr.fit(X_train, y_train)\n",
    "\n",
    "# 预测\n",
    "#sgdr_y_predict = sgdr.predict(X_test)\n",
    "\n",
    "sgdr.coef_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The value of default measurement of SGDRegressor on test is 0.891665509505\n",
      "The value of default measurement of SGDRegressor on train is 0.945204836482\n"
     ]
    }
   ],
   "source": [
    "# 使用SGDRegressor模型自带的评估模块，并输出评估结果\n",
    "print 'The value of default measurement of SGDRegressor on test is', sgdr.score(X_test, y_test)\n",
    "print 'The value of default measurement of SGDRegressor on train is', sgdr.score(X_train, y_train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 正则化的线性回归（L2正则 --> 岭回归）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 岭回归／L2正则\n",
    "#class sklearn.linear_model.RidgeCV(alphas=(0.1, 1.0, 10.0), fit_intercept=True, \n",
    "#                                  normalize=False, scoring=None, cv=None, gcv_mode=None, \n",
    "#                                  store_cv_values=False)\n",
    "from sklearn.linear_model import  RidgeCV\n",
    "\n",
    "alphas = [0.01, 0.1, 1, 10, 20, 40, 80,100, 200, 300, 400]\n",
    "reg = RidgeCV(alphas=alphas, store_cv_values=True)   \n",
    "rd_model = reg.fit(X, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEKCAYAAADjDHn2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0c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Vxg+fn5L4A/Y7jHMwP8v5HxZ3Y1SL3yMJS07AvA5UkG3XmEFwJfAv4I+EfduYu/\nCvzdkTl3AU/tlv8y8GPgB924S49xPzPA0jmPX+i2v5rHA9/t9mx+CRiM9D2N4dfgSr1yz0Ja9jGG\n5yP+hOG7/X9VVd9L8hHgRQxflL/O8JvSftDN+QTD8Ph0Vf1Jki8De4B9wB8f435+DFyYZHe3ncsb\ndb0H+EiSVwOf7eYv+bmuBqlXXnVWmkCSx1bVj5I8keHexiVdkPwEwxfwS7pzHZNs60dV9dgTVNcX\ngG1Vdd+J2J50LO5ZSJP5wyRPADYA76iq7wFU1QNJrmb4Xd3fOZkFdYfK3m1Q6GRwz0KS1OQJbklS\nk2EhSWoyLCRJTYaFJKnJsJAkNRkWkqSm/w9jTKcTv9/XoAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xfc2eb00>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('alpha is:', 10.0)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([  3.15770865e-03,   2.14765354e-02,   8.15519580e-03,\n",
       "         1.34831503e-03,   1.22590274e-04,   2.85333366e-03,\n",
       "         5.54245197e-03,   1.51658611e-02,   2.25927561e-02,\n",
       "         5.99666686e-02,   1.82108555e-02,   1.06898809e-02,\n",
       "        -6.96606162e-04,  -1.03120125e-02,  -2.27381211e-04,\n",
       "         1.09268082e-03,   1.59396507e-02,   6.65071664e-03,\n",
       "         2.26500510e-02,  -1.99406661e-03,   3.66003106e-03,\n",
       "        -9.33650959e-03,   1.50677321e-02,   1.14895628e-02,\n",
       "         8.41043996e-03,   9.49986772e-04,   2.73739115e-03,\n",
       "         7.32440224e-03,  -5.07273620e-03,  -2.27155377e-03,\n",
       "         2.04355263e-04,   6.36586625e-03,  -1.14184218e-02,\n",
       "        -1.86755896e-02,   2.78815329e-03,   9.38565659e-03,\n",
       "         2.53749187e-02,   5.24790732e-03,   7.33109586e-03,\n",
       "        -5.57936246e-04,   3.61613307e-03,  -3.15718184e-03,\n",
       "         9.48869020e-03,  -4.02759607e-03,   6.12237031e-03,\n",
       "         1.11785300e-02,   2.49048207e-03,   1.49231453e-03,\n",
       "         4.94845917e-04,   9.62087995e-03,  -4.88462976e-03,\n",
       "        -2.99419064e-02,   1.26294530e-03,  -2.43931717e-03,\n",
       "         2.33336066e-02,  -4.20598103e-03,   1.10619499e-02,\n",
       "         1.05703128e-03,   5.24790732e-03,  -1.08226456e-02,\n",
       "         3.96401971e-02,  -1.52065807e-03,   1.29521036e-02,\n",
       "         7.12323538e-03,   7.68585468e-03,  -3.78393834e-03,\n",
       "         6.93726255e-03,  -1.75301959e-02,   8.29881875e-03,\n",
       "         6.58438259e-02,  -1.32835469e-02,   1.26819411e-03,\n",
       "         4.09795110e-02,  -1.16998644e-02,   1.45241864e-02,\n",
       "         4.30770359e-02,  -1.02141913e-02,  -2.55140769e-02,\n",
       "         3.32338953e-02,   4.42831292e-03,   1.03154263e-02,\n",
       "         1.03767276e-02,   3.59367408e-04,   9.03639805e-03,\n",
       "         7.68084425e-03,   2.66398557e-03,  -1.60582383e-03,\n",
       "        -7.18583053e-03,  -1.63458686e-02,   1.88537528e-02,\n",
       "         2.34148459e-02,  -6.96606162e-04,  -6.96606162e-04,\n",
       "        -6.96606162e-04,  -2.13620073e-03,   2.08341654e-02,\n",
       "         2.11373385e-03,   2.15763154e-02,   1.20330980e-02,\n",
       "         6.72860866e-03,  -3.47201072e-02,  -5.61791491e-03,\n",
       "         0.00000000e+00,  -3.09526231e-02,   3.09526231e-02,\n",
       "         0.00000000e+00,  -2.06481008e-02,  -2.04594368e-02,\n",
       "         3.59001224e-02,  -3.54608053e-03,   1.01945998e-02,\n",
       "        -2.98495624e-02,   1.35301380e-02,  -6.28318965e-03,\n",
       "         2.11615099e-02,   0.00000000e+00,  -5.98845782e-03,\n",
       "         1.74375577e-03,   6.87403164e-03,   4.18060497e-03,\n",
       "         0.00000000e+00,  -7.10458190e-03,  -9.77485605e-04,\n",
       "         1.27213293e-03,   0.00000000e+00,   3.30895338e-03,\n",
       "         1.59163824e-03,   4.99224302e-03,  -3.54881901e-03,\n",
       "        -7.36372182e-03,   1.01970620e-03,  -1.44303282e-02,\n",
       "        -1.21644407e-03,  -2.73113194e-02,   5.12020865e-02,\n",
       "        -9.60922292e-03,  -1.43961010e-03,   1.43853476e-04,\n",
       "         3.88686016e-05,   1.27178873e-02,  -2.68659817e-03,\n",
       "        -5.70572528e-04,   2.07138433e-02,  -9.29906687e-03,\n",
       "        -3.19998976e-02,   1.37465207e-02,   0.00000000e+00,\n",
       "        -1.59042231e-02,   4.10015070e-03,  -5.64183284e-03,\n",
       "        -2.09088585e-02,  -9.60922292e-03,   1.92594310e-02,\n",
       "        -7.84573121e-03,  -4.27854982e-03,   8.62372200e-04,\n",
       "        -6.44335512e-03,  -1.01210604e-02,   7.70980964e-03,\n",
       "         9.65788997e-03,   1.35537109e-02,   2.81246713e-02,\n",
       "        -2.51520174e-03,   0.00000000e+00,   1.02632397e-02,\n",
       "        -2.24446464e-02,   1.32800686e-02,  -1.03591909e-02,\n",
       "         9.26052905e-03,   0.00000000e+00,  -4.22624743e-03,\n",
       "        -6.18289880e-03,   1.96610159e-02,   4.32476837e-03,\n",
       "         1.38899733e-02,  -2.74666114e-02,   0.00000000e+00,\n",
       "         9.98192459e-03,  -6.01095374e-03,  -1.92376163e-03,\n",
       "        -2.04720921e-03,   0.00000000e+00,  -2.48180485e-02,\n",
       "         1.08972211e-02,   5.18125471e-03,   1.64695221e-02,\n",
       "        -1.23502919e-02,   1.06312963e-02,  -6.01095374e-03,\n",
       "         0.00000000e+00,   2.99562581e-04,   1.13116631e-02,\n",
       "         1.43685467e-02,  -3.73480138e-02,  -2.97715395e-03,\n",
       "         1.43453954e-02,   0.00000000e+00,  -2.04126678e-02,\n",
       "         1.77625402e-02,  -1.18439264e-02,  -1.81381260e-02,\n",
       "         2.56491372e-02,  -4.94382610e-03,  -4.82240902e-03,\n",
       "         1.67492779e-02,   0.00000000e+00,   8.63548434e-03,\n",
       "         1.87506807e-02,  -1.67447212e-02,  -1.06414438e-02,\n",
       "         0.00000000e+00,   8.98868959e-03,   3.09953196e-02,\n",
       "        -1.96676289e-02,  -1.55251177e-02,  -4.79126261e-03,\n",
       "         0.00000000e+00,   1.71470302e-02,   0.00000000e+00,\n",
       "        -5.07417112e-02,  -1.71154276e-02,   9.10940600e-03,\n",
       "         1.76474102e-02,  -3.33815550e-02,   2.71194852e-03,\n",
       "        -4.49850262e-04,   1.58410420e-02,  -4.42980579e-04,\n",
       "         3.03621878e-02,  -2.97178520e-03,  -6.96086964e-04,\n",
       "         6.25176336e-03,   6.72860866e-03,   0.00000000e+00,\n",
       "        -1.43523676e-01,   5.44873016e-02,   4.03668709e-02,\n",
       "         4.74712723e-02,   1.19823132e-03,   0.00000000e+00,\n",
       "        -3.60031272e-02,   1.49961397e-03,   1.85437922e-03,\n",
       "         3.26491340e-02,   0.00000000e+00,  -8.58720589e-04,\n",
       "         1.69737829e-02,  -1.25483242e-02,   1.05313784e-02,\n",
       "        -1.40981164e-02,   0.00000000e+00,   4.80669085e-03,\n",
       "        -3.50050269e-03,   4.57673091e-03,  -1.12641933e-02,\n",
       "        -2.34957584e-03,   5.06470522e-03,   1.68036643e-03,\n",
       "        -2.43320101e-03,   2.07581950e-02,  -8.95168187e-03,\n",
       "        -6.02260906e-03,  -2.36492467e-03,   0.00000000e+00,\n",
       "        -3.93497057e-02,   7.34686726e-03,  -1.86116406e-03,\n",
       "         4.44932846e-02,   1.71747871e-02,  -1.75538860e-02,\n",
       "         9.17429735e-02,  -4.93700015e-02,  -2.94808131e-02,\n",
       "        -4.04650701e-02,  -9.11741466e-02,  -3.15491306e-02,\n",
       "        -1.26422515e-02,   2.81048593e-02,  -1.86387468e-02,\n",
       "         7.85426053e-03,   6.85485413e-02,  -2.28080401e-02,\n",
       "        -2.62500357e-03,  -1.35492495e-02,  -1.50773170e-02,\n",
       "         2.93275815e-02,   7.97308087e-02,  -1.22626713e-02,\n",
       "         2.40832338e-02,   0.00000000e+00,  -1.86524530e-02,\n",
       "         1.45389869e-02,   9.07481619e-03,  -3.66715947e-03,\n",
       "        -1.99147874e-02,  -3.66562450e-03,   2.22862212e-02,\n",
       "         0.00000000e+00,   1.01408288e-02,  -1.21682940e-02,\n",
       "        -1.52876584e-02,   6.70469448e-03,   1.04481705e-03,\n",
       "         9.56561209e-03,   0.00000000e+00,  -3.47098219e-02,\n",
       "         2.32414949e-02,  -9.51384015e-03,  -1.77542570e-02,\n",
       "         3.68190661e-02,   1.91735808e-03,   0.00000000e+00,\n",
       "        -2.79450121e-02,   2.28529550e-02,   9.79492162e-03,\n",
       "         1.89879242e-02,  -1.35160447e-02,   2.72406874e-04,\n",
       "         2.02244658e-02,   3.92088317e-03,  -3.45924999e-02,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00])"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mse_mean = np.mean(reg.cv_values_, axis = 0)\n",
    "plt.plot(np.log10(alphas), mse_mean.reshape(len(alphas),1)) \n",
    "plt.plot(np.log10(reg.alpha_)*np.ones(3), [0.28, 0.29, 0.30])\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "\n",
    "print ('alpha is:', reg.alpha_)\n",
    "reg.coef_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The value of default measurement of RidgeRegression on train is 0.93612465015\n",
      "RMSE on train is:  0.0998993236156\n"
     ]
    }
   ],
   "source": [
    "# 使用LinearRegression模型自带的评估模块（r2_score），并输出评估结果\n",
    "#print 'The value of default measurement of RidgeRegression on test is', reg.score(X_test, y_test)\n",
    "\n",
    "print 'The value of default measurement of RidgeRegression on train is', reg.score(X, y)\n",
    "\n",
    "\n",
    "rd_y_predict_train = reg.predict(X)\n",
    "#print 'RMSE on test is: ',np.sqrt( mean_squared_error(y_test, reg.predict(X_test)))\n",
    "print 'RMSE on train is: ',np.sqrt( mean_squared_error(y, rd_y_predict_train))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAe8AAAFsCAYAAADlrTG7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3XucXGWd5/HPjxCJQ7jTgUDABASV\nawcbJOsAcSKCggR3VWC5hAEJw2XWkdFRcBx6UHecAXVlYRijICAIAZSBHXUXNgNGWEETzEQgYAKC\nJGRCCMMlIELCb/+o07GSdKeLrurLk/68X69+VdVzTp3zq6eS/tbznNOnIjORJEnl2GSwC5AkSW+O\n4S1JUmEMb0mSCmN4S5JUGMNbkqTCGN6SJBXG8JZ6EBEPRcTkwa5jMEXERyLiqYhYGRETB3C/KyNi\ntx6WnRoR97RoP09ExPtbsS1pIBneGpa6+6W9bihk5t6ZeXcv2xkfERkRm/ZTqYPtEuDczBydmb9c\nd2H12l+uwnZJRHwtIkY0u9Nqf483ux1pY2V4S0PYEPhQ8DbgoV7W2T8zRwOHAccBp/V7VdIwZ3h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71ecA8FHR0d/R7cq1evbtm2\nDG9J0psyadIklixZsubxxRdfzIEHHsh+++3HhRdeCMDLL7/MUUcdxf77788+++zDzJkzgdqot+ty\n2N/5znfYc889Oeyww7j33nvXbO/UU0/llltuWfN49OjRAKxcuZIpU6ZwwAEHsO+++3LbbbetV9vS\npUs59NBDaW9vZ5999uGnP/1pQ6/p7rvv5uijjwags7OT0047jcmTJ7PbbrutFerXXXcdBx10EO3t\n7Zx55plrAvmss86io6ODvffee00fQO3y3xdddBF//Md/zM0339xQLY1w2lyS1LDVq1cza9YsTj/9\ndADuuOMOFi5cyM9//nMyk2OOOYbZs2ezfPlydtppJ374wx8C8MILL6y1naVLl3LhhRcyd+5cttpq\nK973vvcxceLEDe571KhR3HrrrWy55ZY8++yzHHzwwRxzzDFrnfz1ve99jyOOOILPf/7zrF69mlde\neaVPr/ORRx7hrrvu4qWXXuId73gHZ511FosWLWLmzJnce++9jBw5krPPPpvrr7+eU045hS9/+cts\nu+22rF69milTpjB//nz222+/NXXfc889faqjJ4a3JKlXv/vd72hvb+eJJ57g3e9+N4cffjhQC+87\n7rhjTfCuXLmShQsXcsghh/DpT3+az372sxx99NEccsgha23v/vvvZ/LkybS11b5A67jjjuPXv/71\nBmvITC644AJmz57NJptswpIlS1i2bBk77rjjmnUOPPBATjvtNF5//XWOPfZY2tvb+/R6jzrqKDbb\nbDM222wzxowZw7Jly5g1axZz587lwAMPXNMnY8aMAeCmm25ixowZrFq1iqVLl/Lwww+vCe/jjjuu\nTzVsiNPmkqRedR3zfvLJJ3nttdfWHPPOTM4//3zmzZvHvHnzWLRoEaeffjp77rknc+fOZd999+X8\n88/noosuWm+bPf251Kabbsobb7yxZvuvvfYaANdffz3Lly9n7ty5zJs3jx122GG9v5U+9NBDmT17\nNjvvvDMnn3wy1157bZ9e72abbbbm/ogRI1i1ahWZybRp09a81kcffZTOzk5+85vfcMkllzBr1izm\nz5/PUUcdtVZdm2++eZ9q2BBH3pI2Om/mbOxWn7m9sdtqq6249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bwliSpMIa3JEmFMbwlSSrM/wcNDW7gvHJGCAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xfc34518>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#在训练集上观察预测残差的分布，看是否符合模型假设：噪声为0均值的高斯噪声\n",
    "f, ax = plt.subplots(figsize=(7, 5)) \n",
    "f.tight_layout() \n",
    "ax.hist(y - rd_y_predict_train,bins=40, label='Residuals Linear', color='b', alpha=.5); \n",
    "ax.set_title(\"Histogram of Residuals\") \n",
    "ax.legend(loc='best');"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 正则化的线性回归（L1正则 --> Lasso）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LassoCV(alphas=[0.01, 0.1, 1, 10, 100], copy_X=True, cv=None, eps=0.001,\n",
       "    fit_intercept=True, max_iter=1000, n_alphas=100, n_jobs=1,\n",
       "    normalize=False, positive=False, precompute='auto', random_state=None,\n",
       "    selection='cyclic', tol=0.0001, verbose=False)"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#### Lasso／L1正则\n",
    "# class sklearn.linear_model.LassoCV(eps=0.001, n_alphas=100, alphas=None, fit_intercept=True, \n",
    "#                                    normalize=False, precompute=’auto’, max_iter=1000, \n",
    "#                                    tol=0.0001, copy_X=True, cv=None, verbose=False, n_jobs=1,\n",
    "#                                    positive=False, random_state=None, selection=’cyclic’)\n",
    "from sklearn.linear_model import LassoCV\n",
    "\n",
    "alphas = [0.01, 0.1, 1, 10,100]\n",
    "\n",
    "lasso = LassoCV(alphas=alphas)   \n",
    "lasso.fit(X_train, y_train)       "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsA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4PaTQOIF4U7eXkW8oADa\nAw+Z2flAFXBawvjdxC+5IhIqlYXIZ+qahKi+yYmOEr/eE2aWB/wzMMbd95vZ4yeXJZF4zZ3jwd9V\nfPbz+U/Er8d1HvGjAccSxncIMoiESoehRD6zDLjZzDKC8wgTiF/s703iEwO1M7N+xKfVPGk9MDK4\n3Q04DJQH466r43XaEb/iLMCtwfPXpzuwI9iz+TrxaVJPOo2WccVhSXPasxD5zAvEz0d8QPy3/X9x\n951m9jxwFfH/lD8hPjtZebDOn4iXx2vu/oGZvUf8iqTFwFt1vM5h4CwzWxU8z81Jcs0Bnjezm4hf\nEfZwwrIrggwiodJVZ0VSYGZdPD4zWm/iexuXB0XSkfh/4JcH5zpSea5D7t6liXItA6a4+/6meD6R\numjPQiQ1L5pZDyAL+LG77wRw96Nm9gPi8xxvac5AwaGyn6kopDloz0JERJLSCW4REUlKZSEiIkmp\nLEREJCmVhYiIJKWyEBGRpFQWIiKS1P8HBxgrSXLrU2oAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10371588>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('alpha is:', 0.01)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([  0.00000000e+00,   1.39456165e-02,   5.65648212e-03,\n",
       "        -0.00000000e+00,  -2.53889040e-03,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         6.74994780e-02,   1.99826891e-02,   2.02592377e-03,\n",
       "         5.17865241e-06,  -0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,   1.06511129e-02,   0.00000000e+00,\n",
       "         3.38339055e-02,  -0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,   1.35617884e-02,\n",
       "         3.87462770e-03,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "        -1.58210083e-02,   9.84323910e-03,   0.00000000e+00,\n",
       "         2.18518539e-02,   8.44746359e-05,   1.29356841e-02,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   2.23725915e-03,\n",
       "         6.09008920e-03,   2.62838306e-03,  -0.00000000e+00,\n",
       "         0.00000000e+00,   4.05867173e-03,  -0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,   0.00000000e+00,\n",
       "         5.65396029e-02,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   1.32233022e-02,   1.02473016e-02,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   3.52971184e-03,   0.00000000e+00,\n",
       "         1.28383497e-02,   1.27477650e-02,   0.00000000e+00,\n",
       "         1.05629376e-01,   0.00000000e+00,   0.00000000e+00,\n",
       "         6.91766167e-02,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   1.11835169e-02,\n",
       "         2.27851218e-02,   0.00000000e+00,   5.66454054e-03,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   1.04834294e-02,   1.80106884e-03,\n",
       "         0.00000000e+00,   6.96400755e-03,   2.88329520e-16,\n",
       "         3.05110603e-18,   4.25349098e-03,   0.00000000e+00,\n",
       "         4.29361386e-03,   0.00000000e+00,  -0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00])"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mses = np.mean(lasso.mse_path_, axis = 1)\n",
    "plt.plot(np.log10(lasso.alphas_), mses) \n",
    "#plt.plot(np.log10(lasso.alphas_)*np.ones(3), [0.3, 0.4, 1.0])\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()    \n",
    "            \n",
    "print ('alpha is:', lasso.alpha_)\n",
    "lasso.coef_  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The value of default measurement of Lasso Regression on test is 0.860072773465\n",
      "The value of default measurement of Lasso Regression on train is 0.902579433993\n"
     ]
    }
   ],
   "source": [
    "# 使用LinearRegression模型自带的评估模块（r2_score），并输出评估结果\n",
    "print 'The value of default measurement of Lasso Regression on test is', lasso.score(X_test, y_test)\n",
    "print 'The value of default measurement of Lasso Regression on train is', lasso.score(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>SalePrice</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1461</td>\n",
       "      <td>112264.035</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1462</td>\n",
       "      <td>155418.201</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1463</td>\n",
       "      <td>189978.675</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1464</td>\n",
       "      <td>188682.451</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1465</td>\n",
       "      <td>191958.564</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     Id  SalePrice\n",
       "0  1461 112264.035\n",
       "1  1462 155418.201\n",
       "2  1463 189978.675\n",
       "3  1464 188682.451\n",
       "4  1465 191958.564"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_2test = FE_test.drop(['Id'], axis=1)\n",
    "\n",
    "# 综合考虑RMSE 和 r2_score评估，最终采用 岭回归 线性回归模型\n",
    "lr_y_predict_test = rd_model.predict(X_2test)\n",
    "\n",
    "submission = pd.DataFrame()\n",
    "submission['Id'] = FE_test.Id\n",
    "submission['SalePrice'] = np.exp(lr_y_predict_test)\n",
    "\n",
    "submission.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "collapsed": true,
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "submission.to_csv('ridge_pre_price.csv', index = False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
